Reputation: 51
When I try to http://domain.test/logout then showing "The GET method is not supported for this route. Supported methods: POST"
But normal logout with post method working perfectly. How can I change the /logout route Post to get. in Jetstream, fortify
Upvotes: 2
Views: 7466
Reputation: 91
For Anyone Facing This Problem in Laravel Jetstream use this Code
<form method="POST" action="{{ route('logout') }}">
@csrf
<x-jet-dropdown-link href="{{ route('logout') }}" onclick="event.preventDefault(); this.closest('form').submit();">
<i class="fa fa-sign-out"></i>{{ __('Logout') }}
</x-jet-dropdown-link>
</form>
Upvotes: 1
Reputation: 1
You should put them in the base.blade.php file or the file where the logout form is supposed to be
Upvotes: 0
Reputation: 139
If still anyone is looking for it you can try this. In Laravel 8 get method doesn't support logout route you can try post method like below.
<form method="POST" action="{{ route('logout') }}">
@csrf
<div class="nav-item">
<a class="nav-link" href="{{ route('logout') }}" onclick="event.preventDefault();
this.closest('form').submit(); " role="button">
<i class="fas fa-sign-out-alt"></i>
{{ __('Log Out') }}
</a>
</div>
</form>
You can also try this by check in if it's login then it will show you logout otherwise it will show you login .
@if (auth()->id())
<form method="POST" action="{{ route('logout') }}">
@csrf
<div class="nav-item">
<a class="nav-link" href="{{ route('logout') }}" onclick="event.preventDefault();
this.closest('form').submit(); " role="button">
<i class="fas fa-sign-out-alt"></i>
{{ __('Log Out') }}
</a>
</div>
</form>
@else
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}" role="button">
<i class="fas fa-sign-in-alt"></i>
Login
</a>
</li>
@endif
Upvotes: 3
Reputation: 762
if you list your routes using php artisan route:list
you'll see that logout route is defined for POST, so you just need to submit a form to this route in order to fire logout.
POST | logout | Laravel\Fortify\Http\Controllers\AuthenticatedSessionController@destroy | web
Now if you wish to convert that function to respond to GET method, you'll need to change that route in /vendor/laravel/fortify/routes/route.php
I have not tested it in any way, but the method and routes are there.
Upvotes: 2