0
votes

Trying to figure out why my DELETE request not working..I'm using Postman and RESTClient in Firefox to send this DELETE request

DELETE http://localhost:8000/api/access-tokens

and I get the same error :

(1/1) MethodNotAllowedHttpException in RouteCollection.php (line 252) at RouteCollection->methodNotAllowed(array('GET', 'HEAD'))in >RouteCollection.php (line 239)

Here is my routes/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');

});

Here is the output of php artisan route:list

|        | DELETE   | api/access-tokens            |                      | App\Http\Controllers\AuthController@logout                             | api,jwt.auth |
2
Probably you have to add a _token and a _method field to the request. _method should have DELETE as value. - Laerte
use POST method - Adam Kozlowski
I use JWT tokens to authenticate, i'm sending an access token in the Header. I tried adding _method in the Request's Body but no luck! - Tudor Danes
I can not use POST method, these are the project's requirements - Tudor Danes
If you want to debug this issue, I suggest to create the same route but instead of post or delete, use any and check the request method inside your controller. - Paul Santos

2 Answers

0
votes

You are posting your data as GET, try add method field

{{ method_field('DELETE') }}
0
votes

The problem was in my controller..commented one line and it works! Thank you all