Laravel - RouteCollection.php中的MethodNotAllowedHttpException

时间:2016-01-13 13:49:21

标签: php laravel post routes laravel-5

我正在使用Laravel 5.2并收到此消息:

MethodNotAllowedHttpException in RouteCollection.php at line 219:
at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 206

我试图更新用户,这是我的路线列表: enter image description here

这是我的路线和控制器的样子:

路线:

Route::get('user/profile/{userid}', 'UserController@show');
Route::get('user/edit/{id}', 'UserController@edit');
Route::post('user/edit/{id}', 'UserController@store');

UserController中:

public function update(Request $request, $id)
{
    $user = User::findOrFail($id);

    $this->validate($request, [
        'voornaam' => 'required|max:255',
        'email' => 'required|email|max:255|unique:klanten',
        'achternaam' => 'required|max:255',
        'geboortedatum' => 'required|max:10',
        'niveau' => 'required|max:255',
        'adres' => 'required|max:255',
        'postcode' => 'required|max:6',
        'woonplaats' => 'required|max:255',
        'telefoonnummer' => 'required|max:10'
    ]);

    $input = $request->all();
    $user->fill($input)->save();

    Session::flash('flash_message', 'Gebruiker succesvol gewijzigd!!');

    return redirect()->back();
}

public function edit($id)
{
    $user = User::findOrFail($id);
    return view('user.edit', ['user' => $user]);
}

我没有使用html表单构建器,但我读到如果您不使用表单构建器,则可以在视图中的表单中使用此行:

 <input name="_method" type="hidden" value="PATCH">

0 个答案:

没有答案