我正在使用PATCH / DELETE请求,但无法继续执行所需的请求。
错误:MethodNotAllowedHttpException
当我完全切换到POST-Requests时,我收到的页面不再是主动错误。
路线-文件
Route::group(['prefix' => '/users', 'namespace' => 'Users', 'as' => 'administrators.users.'], function () {
Route::get('/', 'UsersController@index')->name('index');
Route::get('/create', 'UsersController@create')->name('create');
Route::post('/create', 'UsersController@store')->name('store');
Route::get('/edit/{user}', 'UsersController@edit')->name('edit');
Route::patch('/update/{user}', 'UsersController@update')->name('update');
Route::patch('/activate/{user}', 'UsersController@activate')->name('activate');
Route::patch('/deactivate/{user}', 'UsersController@deactivate')->name('deactivate');
Route::delete('/delete/{user}', 'UsersController@delete')->name('delete');
});
查看表格请求
<a href="#" onclick="event.preventDefault();document.getElementById('activate-form').submit();" class="badge badge-success">Activate</a>
<form id="activate-form" action="{{ route('administrators.users.activate', $user) }}" method="POST"
style="display: none;">
{{ csrf_field() }}
{{ method_field('PATCH') }}
</form>
控制器
public function activate(User $user)
{
if(!auth()->user()->isSameAs($user))
{
$user->active = true;
$user->save();
}
return back();
}