i'm new to laravel, and i found few decent tutorials to help me understand and get started with it.
the problem is-> whenever i want to use the post method this exception raises MethodNotAllowedHttpException
but unlike, maybe 99% of who asked similar questions, in my case it says the exception is in RouteCollection.php line 218
, which is unusual but not to laravel 5.2.x
the following is the methode post in routes.php:
Route::post('/ajouter_produit',
[
'uses'=>'ProductController@addProduct',
'as'=>'ajouter_produit',
]);
i even tried adding this method to a middleware route group but the problem remained.
this is my controller:
public function addProduct (Request $request)
{
$this->validate($request, [
'label'=>'required|alpha',
'prix'=>'required|numeric',
]);
$prod = new Product();
$prod->label=$request['label'];
$prod->type=$request['type'];
$prod->prix=$request['prix'];
$prod->save();
return view('welcome');
}
and this is my form:
<form action="{{ route('ajouter_produit') }}" method="post" >
<input type="text" name="label" id="label"/>
<select name="type" id="type">
<option value="1">Par unité</option>
<option value="2" selected>Par kilo</option>
</select>
<input type="text" name="prix" id="prix"/>
<button type="submit">Ajouter</button>
<input type="hidden" value="{{ Session::token() }}" name="_token"/>
i also tried this but it raised the same problem:
Route::post('/trypost', function () {
return 'hello post';
});
can you please help me !!
if you need any other source just ask for it.
Every effort will be much appreciated. thank you
php artisan route:list
– Ganesh Ghalame