laravel向我显示此错误此路由不支持POST方法。支持的方法:GET,HEAD,PUT,DELETE

时间:2019-03-24 14:33:23

标签: laravel

laravel当我以create的形式提交时向我显示此错误 “此路由不支持POST方法。受支持的方法:GET,HEAD,PUT,DELETE。” 我在一页上工作parent.blade .php,表单显示在同一页面上 路线:

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');

这些是控制器方法:

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');    
}

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

尝试

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

刀片

商店

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

答案 2 :(得分:0)

尝试更改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');

您认为

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

 </form>