Home > Mobile >  Laravel 9 Getting error Upload Form Submit to Database and give an error message
Laravel 9 Getting error Upload Form Submit to Database and give an error message

Time:04-11

i have a problem upload my form to database using post method in route::middleware and get an error like this The POST method is not supported for this route. Supported methods: GET, HEAD.

i dont know where to check it again.please help me.i already do solution from another post in here but it still not solve.

web.php

Route::middleware(['auth', 'isAdmin'])->group(function () {
Route::get('/dashboard','App\Http\Controllers\Admin\FrontendController@index');

Route::get('categories','App\Http\Controllers\Admin\CategoryController@index');
Route::get('add-category','App\Http\Controllers\Admin\CategoryController@add');
Route::get('insert-category','App\Http\Controllers\Admin\CategoryController@insert'); });

CategoryController.php

public function insert(Request $request)
{
    $category = new Category();
    if($request->hasFile('image')->isValid())
    // {
    //     $file = $request->file('image');
    //     $ext = $file->getClientOriginalExtension();
    //     $filename = time().'.'.$ext;
    //     $file->move('assets/uploads/category',$filename);
    //     $category->image = $filename;

    // }


    $category->name = $request->input('name');
    $category->slug = $request->input('slug');
    $category->description = $request->input('description');
    $category->status = $request->input('status') == TRUE ? '1':'0';
    $category->popular = $request->input('popular') == TRUE ? '1':'0';
    $category->meta_title = $request->input('meta_title');
    $category->meta_keywords = $request->input('meta_keywords');
    $category->meta_descrip = $request->input('meta_description');
    $category->save();
    return redirect('/dashboard')->with('status',"Category Added Succesfully");
}

this is Model Category.php

class Category extends Model{
use HasFactory;

protected $table = 'categories';
protected $fillable = [
    'name',
    'slug',
    'description',
    'status',
    'popular',
    'image',
    'meta_title',
    'meta_descrip',
    'meta_keywords',
];}

and this is my form add.blade.php

<form action="{{ url('insert-category') }}" method="POST" enctype="multipart/form-data">
            @csrf
            <div >
                <div >
                    <label for="">Name</label>
                    <input type="text"  name="name">
                </div>
                <div >
                    <label for="">Slug</label>
                    <input type="text"  name="slug">
                </div>
                <div >
                    <label for="">Description</label>
                    <textarea name="description" rows="3" ></textarea>
                </div>
                <div >
                    <label for="">Status</label>
                    <input type="checkbox"  name="status">
                </div>
                <div >
                    <label for="">Popular</label>
                    <input type="checkbox"  name="popular">
                </div>
                <div >
                    <label for="">Meta_title</label>
                    <input type="text"  name="meta_title">
                </div>
                <div >
                    <label for="">Meta_Keyword</label>
                    <textarea name="meta_keywords" rows="3" ></textarea>
                </div>
                <div >
                    <label for="">Meta_Description</label>
                    <textarea name="meta_description" rows="3" ></textarea>
                </div>
                <div >
                    <input type="file"  name="image">
                </div>
                <div >
                    <button type="submit" >Submit</button>
                </div>

            </div>
    </div>
    </form>

CodePudding user response:

insert-category should be a POST route instead of a GET i-e

Route::post('insert-category','App\Http\Controllers\Admin\CategoryController@insert'); });
  • Related