我在主页上有两个按钮 - 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
时,我可以成功注册用户,因此表单效果很好。
ProfessionController
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
并在那里成功运行)时,会抛出错误:
RouteCollection.php第201行中的MethodNotAllowedHttpException:
我在哪里错过了?
答案 0 :(得分:1)
根据您的问题,我认为您的表单中存在错误。 在您的路线中,您正在接收和发布请求。
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