Laravel 5.4 - DELETE请求的MethodNotAllowedHTTPException

时间:2017-12-14 18:42:10

标签: php laravel rest

试图找出我的DELETE请求无法正常工作的原因..我在Firefox中使用Postman和RESTClient发送此DELETE请求

删除http://localhost:8000/api/access-tokens

我得到同样的错误:

  

(1/1)MethodNotAllowedHttpException   在RouteCollection.php中(第252行)   在RouteCollection-> methodNotAllowed(array('GET','HEAD'))> RouteCollection.php(第239行)

这是我的路线/ api.php:

Route::post('access-tokens', 'AuthController@login');

// Register
Route::post('users', 'AuthController@register');

Route::post('recover', 'AuthController@recover');
Route::group(['middleware' => ['jwt.auth']], function() {
Route::delete('access-tokens', 'AuthController@logout');
Route::get('me', function(Request $request) {
    return $request->user();
});

Route::post('access-tokens/refresh', 'AuthController@refreshToken');
Route::post('ideas', 'IdeasController@store');

});

这是php artisan route的输出:list

|        | DELETE   | api/access-tokens            |                      | App\Http\Controllers\AuthController@logout                             | api,jwt.auth |

2 个答案:

答案 0 :(得分:0)

您将数据发布为GET,请尝试添加方法字段

{{ method_field('DELETE') }}

答案 1 :(得分:0)

问题出在我的控制器上。评论一行,它的工作原理! 谢谢大家