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

12,704

Solution 1

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>

Solution 2

try

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

blade

store

     <form method="POST" action="{{route('parents.store')}}">
     {{ csrf_field() }}
     ...
     </form>
Share:
12,704

Related videos on Youtube

anas
Author by

anas

Updated on June 04, 2022

Comments

  • anas
    anas almost 2 years

    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');    
    }
    
    • rpm192
      rpm192 about 5 years
      Add your view please.
    • dvr
      dvr almost 5 years
      To make sure everything is up to date, do: php artisan route:clear
  • rameez.hashmi
    rameez.hashmi about 5 years
    add this code in your html form <input type="hidden" name="_token" value="{{ csrf_token() }}">