Reputation: 13
laravel show me this error when i submit in the form of create "The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, DELETE. " I'm working on one page parent.blade .php the forms appear in the same page routes :
Route::get('parents', 'ParentController@index');
Route::get('parents/create', 'ParentController@create');
Route::post('parents', 'ParentController@store');
Route::get('parents/{id}/edit', 'ParentController@edit');
Route::put('parents/{id}', 'ParentController@update');
Route::delete('parents/{id}', 'ParentController@destroy');
And these are controller methods:
public function create()
{
return view('admin.parent');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$parent = new Parent();
$parent->nom = $request->input('nom');
$parent->nom = $request->input('prenom');
$parent->nom = $request->input('adresse');
$parent->nom = $request->input('num-tel');
$parent->nom = $request->input('email');
$parent->nom = $request->input('login');
$parent->nom = $request->input('password');
$parent->save();
return view('admin.parent');
}
Upvotes: 2
Views: 12871
Reputation: 825
So you need to understand the cycle of Laravel routes.
Route::post('/any-url', 'CONTROLLER@functionToCAll')
this means that on the HTML side you can use method="POST" in the Post Section to trigger
<form method="POST" action="{{route('YourRouteName')}}">
{{ csrf_field() }}
</form>
if you want to trigger the delete or update function of the controller you had to include
and the best way to use these is after tag
<form method="POST" action="{{route('YourRouteName')}}">
{{ method_field('PATCH') }}
Note: you can also use Route::Any for efficiency
Route:any(['POST','GET','PUT'], 'CONTROLLR@Function');
Upvotes: 0
Reputation: 1
I also had this
Route::get('/student/store', [StudentController::class, 'store'])->name('student.store');
and I changed it to
Route::post('/student/store', [StudentController::class, 'store'])->name('student.store');
you see I had get
, I changed it to post
.
Upvotes: 0
Reputation: 1814
Try to change the order of routes in web.php
Route::get('parents', 'ParentController@index');
Route::post('parents', 'ParentController@store')->name('parents.store');
Route::get('parents/create', 'ParentController@create');
Route::get('parents/{id}/edit', 'ParentController@edit');
Route::put('parents/{id}', 'ParentController@update');
Route::delete('parents/{id}', 'ParentController@destroy');
In your view
<form method="POST" action="{{route('parents.store')}}">
{{ csrf_field() }}
</form>
Upvotes: 1
Reputation: 349
try
Route::resource('parents','ParentController')
blade
<form method="POST" action="{{route('parents.store')}}">
{{ csrf_field() }}
...
</form>
Upvotes: 1