Open pereiracinthiag opened 5 years ago
I've done a similar problem, when I created a route in GET and then I went to POST it cleans the laravel cache Try using the following code in your project:
php artisan cache:clear
php artisan route:cache
php artisan config:cache
php artisan view:clear
I've done a similar problem, when I created a route in GET and then I went to POST it cleans the laravel cache Try using the following code in your project:
php artisan cache:clear php artisan route:cache php artisan config:cache php artisan view:clear
Thanks for the tip. But it didn't work for me =/
@pereiracinthiag in your routes/api.php
you've set up all the routes as POST
routes... which is why it is not allowing GET
. If you want to use GET
for me
, you'd have to change it to this:
Route::group([
'middleware' => 'api',
'prefix' => 'auth'
], function ($router) {
Route::post('login', 'Api\AuthController@login')->name('login');
Route::post('logout', 'Api\AuthController@logout')->name('logout');
Route::post('refresh', 'Api\AuthController@refresh')->name('refresh');
Route::get('me', 'Api\AuthController@me')->name('me');
});
It's pretty standard to use POST
for logout.
@pereiracinthiag Try to solve your problem like this.
app > Http > Middleware > Authenticate.php
routes > api.php make route Route::get('change route name'), function (){ return response()->json(['error' => 'unauthenticated']); });
@pereiracinthiag I came across this issue before in 5.8, consider specifying request method type in your html tag <html method="POST">
rather than using @method('POST').
Error still not fixed
It work for me. Change the 'middleware' => 'api', to 'middleware' => 'jwt.auth'
i have the same error but in my case, the error only occurs when i Clicked the URL and pressing enter. the error shows, but if hitting f5 the page refreshes normally no error at all. how to fix this error please help. im using POST method.
Go to vendor>Laravel>framework>src>illuminate>routing>Router.php
Change line 1154: $this->post('logout', 'Auth\LoginController@logout')->name('logout');
to $this->get('logout', 'Auth\LoginController@logout')->name('logout');
This solved the problem for me!
@konte21 Sir still doesn't work, maybe because my vendor folder greyed and when i changed the line 1154 it didn't take effect.
my scenario is like this, i have blade template and has a form and uses post method action="home/something", after clicking submit, the current page is in /home/something and displays some information but when i click the url bar and the url is all selected then pressing button enter the "The GET method is not supported for this route. Supported methods: POST." shows.
Any update to this? I am also experiencing the same issue.
Any update to this? I am also experiencing the same issue.
This happened to me today and it was a really silly mistake... I was using http instead of https on my API requests
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException The GET method is not supported for this route. Supported methods: POST.
I am using the Stripe payment gateway when I click on Pay then I am getting this error also- my controller cose here- form route-
The problem is with authentication. The routes are fine..See the auth type you are using and provide the credentials for you to hit that Get or Post end point. https://laracasts.com/discuss/channels/laravel/routing-in-laravel-6-methodnotallowedhttpexception
Just make sure headers accept value set to application/json.
and now everything works fine.
I think you haven't set token while sending a request so you should be sure to send with token for requests such as logout, me, refresh
@pereiracinthiag I also face similar error "GET method is not supported for this route. Supported methods: POST." I create the new route for that method/function with a different name and it works.
Any update to this? I am also experiencing the same issue.
This happened to me today and it was a really silly mistake... I was using http instead of https on my API requests
This solved my problem! Thanks!
Can you explain how to change http to https on the API rest. Thanks in advance!
Can you explain how to change http to https on the API rest. Thanks in advance!
I just replaced http with https in URLs.
Thanks for your response. In fact,I am using https. The error appears when I do the laravel the validation of the form. So, at the end I decided do the validation using Jquery.
@pereiracinthiag in your
routes/api.php
you've set up all the routes asPOST
routes... which is why it is not allowingGET
. If you want to useGET
forme
, you'd have to change it to this:Route::group([ 'middleware' => 'api', 'prefix' => 'auth' ], function ($router) { Route::post('login', 'Api\AuthController@login')->name('login'); Route::post('logout', 'Api\AuthController@logout')->name('logout'); Route::post('refresh', 'Api\AuthController@refresh')->name('refresh'); Route::get('me', 'Api\AuthController@me')->name('me'); });
It's pretty standard to use
POST
for logout.
This Solution worked for me thanks
Try this, go to file vendor/laravel/framework/src/Illuminate/Routing/CompiledRouteCollection, line 159
Replace the code with the following:
$trimmedRequest->server->set('REQUEST_URI', $parts[0].(isset($parts[1]) ? '?'.$parts[1] : ''));
It is not a good choice to change the vendor codes, but until the correction comes out this may be an alternative.
Same issue here.
Here's my stackoverflow question: https://stackoverflow.com/questions/63389765/api-405-method-not-allowed-on-laravel-7-with-tymon-jwt-auth?noredirect=1#comment112089868_63389765
@pereiracinthiag in your routes/api.php you've set up all the routes as POST routes... which is why it is not allowing GET. If you want to use GET for me, you'd have to change it to this:
Route::group([
'middleware' => 'api',
'prefix' => 'auth'
], function ($router) {
Route::post('login', 'Api\AuthController@login')->name('login');
Route::post('logout', 'Api\AuthController@logout')->name('logout');
Route::post('refresh', 'Api\AuthController@refresh')->name('refresh');
Route::get('me', 'Api\AuthController@me')->name('me');
});
This worked for me too. Thanks
Route::get('/logout', 'Auth\LoginController@logout');
Route::get('/logout', 'Auth\LoginController@logout');
That won't work very well for Laravel 8, see Basic Routing
Route::get('/logout',[LoginController::class, 'logout'] );
just make sure that Headers accept application/json
and also make sure that the route grouping is
'middleware' => 'api',
'prefix' => 'auth'
This worked for me class AuthController extends Controller { /**
i got same error on my hosting which is on linux
i change my URL from http://your-domain.com/api/post-test/
to http://your-domain.com/api/post-test
i just remove /
and it works like charm
Route::get('/logout', 'Auth\LoginController@logout');
work for me in Laravel 8 using : Route::get('/logout', [LoginController::class, 'logout']);
just make sure that Headers accept application/json
@YoussefKafa @islamMaruf I have experienced the similar issue, can you please explain the reasoning behind it? I can not fully understand why not having an Accept
header explicitly set to application/json
triggers MethodNotAllowedException
, it doesn't sound logical to me.
I've done a similar problem, when I created a route in GET and then I went to POST it cleans the laravel cache Try using the following code in your project:
php artisan cache:clear php artisan route:cache php artisan config:cache php artisan view:clear
this worked for me thankx
@pereiracinthiag in your
routes/api.php
you've set up all the routes asPOST
routes... which is why it is not allowingGET
. If you want to useGET
forme
, you'd have to change it to this:Route::group([ 'middleware' => 'api', 'prefix' => 'auth' ], function ($router) { Route::post('login', 'Api\AuthController@login')->name('login'); Route::post('logout', 'Api\AuthController@logout')->name('logout'); Route::post('refresh', 'Api\AuthController@refresh')->name('refresh'); Route::get('me', 'Api\AuthController@me')->name('me'); });
It's pretty standard to use
POST
for logout.
this one solved my problem, thanks a lot :')
Go to vendor>Laravel>framework>src>illuminate>routing>Router.php
Change line 1154: $this->post('logout', 'Auth\LoginController@logout')->name('logout');
to $this->get('logout', 'Auth\LoginController@logout')->name('logout');
This solved the problem for me!
I do not recommend change the code inside vendor folder, it will be replaced on any update or install
i have the same problem whit laravel 10 because i try to catch the local connection but i have the problem abaout the method is not support
Same error with me, I use JWT too and I got the same error when I sent a request post to route post the problem here is that I already deployed the API in the host website so I can't use PHP artisan cache: clear
The GET method is not supported for this route. Supported methods: POST
I am trying to get a response in dev.site.com.br/api/auth/me and I have the error Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: The GET method is not supported for this route. Supported methods: POST. in file C:\xampp\htdocs\rnlinked\api\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php on line 256
I am using laravel 5.8 and JWT 1.0 The login method works fine, but the me or logout methods doesn't work.
My environment
| Bug? | yes | Framework | Laravel | Framework version | Laravel Framework 5.8.27 | Package version | "tymon/jwt-auth": "dev-develop" | PHP version | 7.3.3
Below are my codes:
AuthController.php
In routes/api.php
I am using postman and I do a POST request on logout or me or refresh and they get the same error. Only the login method works.