Larave 8 jetstream domain/logout not working

Viewed 3375

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

3 Answers

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.

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

You should put them in the base.blade.php file or the file where the logout form is supposed to be

Related