anas
anas

Reputation: 13

laravel shows me this error The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, DELETE

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

Answers (5)

Mr Talha
Mr Talha

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

  1. {{ method_field('PATCH') }} -> for UPDATE
  2. {{ method_field('DELETE')}} -> For Delete

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

Rahimov
Rahimov

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

rameez.hashmi
rameez.hashmi

Reputation: 29

Route::post('parents', 'ParentController@store'); 

Upvotes: 0

Jithesh Jose
Jithesh Jose

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

bokino12
bokino12

Reputation: 349

try

Route::resource('parents','ParentController')

blade

store

     <form method="POST" action="{{route('parents.store')}}">
     {{ csrf_field() }}
     ...
     </form>

Upvotes: 1

Related Questions