MethodNotAllowedHttpException - Laravel 5.1

MethodNotAllowedHttpException - Laravel 5.1

我在主页上有两个按钮 - Reader & Writer - 将用户引导至注册表知道 profession.

Route::post('register', [
'as' => 'profession_path',
'uses' => 'ProfessionController@displayForm'
]);

Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

当我正常去 .com/auth/register 时,我可以成功注册用户,所以表格可以正常工作。

职业控制器

class ProfessionController extends Controller
{

   public function displayForm()
    {
    $input = \Input::get();
    $profession = $input['profession'];
    return view('auth/register', ['profession' => $profession]);
    }
}  

当我点击按钮并重定向到 .com/register 并识别 $profession 时,它也能成功运行。但是,当我点击注册表单上的提交按钮(通常位于 .com/auth/register 并在那里成功运行)时,它会抛出一个错误:

MethodNotAllowedHttpException in RouteCollection.php line 201:

我哪里漏了?

根据你的问题,我认为你的表格有误。 在你的路线中你正在做 get 和 post request.

Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

通常表单提交是 post 方法,您必须在表单中指定

{{ Form::open(array('method' => 'post')) }}

{{ Form::open(array('method' => 'get')) }} 

如果您使用的是普通 html 那么

<form method="POST" action="http://currenturl" accept-charset="UTF-8">
<form method="GET" action="http://currenturl" accept-charset="UTF-8">

laravel 路由请求如下所示

Route::get() will respond to GET requests.
Route::post() will respond to POST requests.
Route::delete() will respond to DELETE requests (this includes when adding the custom DELETE
Route::put() will respond to PUT requests (this includes when adding the custom PUT
Route::patch() will respond to PATCH requests (this includes when adding the custom PATCH