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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/55324862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:18:33  来源:igfitidea点击:

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

laravel

提问by anas

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 :

当我以创建的形式提交时,laravel 向我显示此错误“此路由不支持 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');

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

回答by bokino12

try

尝试

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

blade

刀刃

store

店铺

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

回答by Jithesh Jose

Try to change the order of routes in web.php

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

回答by rameez.hashmi

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

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