1

try to make a simple insert but i get this error MethodNotAllowedHttpException in RouteCollection.php (line 251) at RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'PUT', 'PATCH', 'DELETE')) in RouteCollection.php (line 238)

this is my form in the view

 <form method="post" action="{{route('product.create')}}" class="form-horizontal" enctype="multipart/form-data"> {!! csrf_field() !!} <fieldset> <!-- Text input--> <div class="form-group"> <label class="col-md-3 control-label" for="name">Name</label> <div class="col-md-9"> <input id="name" name="name" type="text" placeholder="Product name" class="form-control input-md"> </div> </div> <div class="form-group"> <label class="col-md-3 control-label" for="textarea">Description</label> <div class="col-md-9"> <textarea class="form-control" id="textarea" name="description"></textarea> </div> </div> <div class="form-group"> <label class="col-md-3 control-label" for="size">Size</label> <div class="col-md-9"> <select class="form-control" id="size"> <option selected>Choose size...</option> <option value="small">Small</option> <option value="medium">Medium</option> <option value="larg">Larg</option> </select> </div> </div> <div class="form-group"> <label class="col-md-3 control-label" for="category_id">Category</label> <div class="col-md-9"> <select class="form-control" id="category_id"> <option selected>Choose Categories...</option> {{--<option value= "$categories"></option>--}} <option value= "1"> men </option> </select> </div> </div> <div class="form-group"> <label class="col-md-3 control-label" for="image">Image</label> <div class="col-md-9"> <input id="file" name="image" class="input-file" type="file"> </div> </div> <div class="form-group"> <label class="col-md-3 control-label" for="submit"></label> <div class="col-md-9"> <button id="submit" name="submit" class="btn btn-primary">Create</button> </div> </div> </fieldset> </form> 

my route

Route::group(['prefix'=>'admin','middleware'=>'auth'],function(){ Route::get('/' ,function(){ return view('admin.index'); })->name('admin.index'); }); Route::resource('product','ProductsController'); Route::resource('category','CategoriesController'); 

my controller

public function create() { $categories = Category::pluck('name','id'); return view('admin.product.create',compact('categories')); } public function store(Request $request) { $formInput = $request->except('image'); $image = $request->image; if($image){ $imageName = $image->getClientOriginalName(); $image->move('images', $imageName); $formInput['image']=$imageName; } Product::create($formInput); return redirect()->route('admin.index'); } 

any help will be appreciated

0

3 Answers 3

2

should be:

action="{{route('product.store')}}" 

The route product.create expects GET header for showing a register form

Sign up to request clarification or add additional context in comments.

4 Comments

thanks for your replay i change the action now i don't get errors but it doesn't store anything into my DB any suggestion ?
Looks like your form request has errors. Take a look if your controller is getting all expected data. Hint: Try using controllers instead resource controller. This last one is widely used to create APIs
that what i get when i submit the form dd($request); +request: ParameterBag {#41 ▼ #parameters: array:4 [▼ "_token" => "2wDgwkQgH8vVmo283Aod4WbDSsHd5o3Ev7Gx8e57" "name" => "test name" "description" => "test DescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescription" "submit" => null ] }
i get only 2 result well i have in my form more size, image , Category and Image
0

i forget to add name to the form now after adding name i get alle field except image

Comments

0

I tried all above answers and still had this problem. So I found out that my model was requiring the "fillable" property:

protected $fillable = ['name', 'status', 'etc','etc2']; 

This solved the issue and now I can post/put/delete.

Also, in my routes file instead of using one route to each action, I simply use, for example:

 Route::resource('user', 'v1\UserController'); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.