2

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

anower hasan
  • 51
  • 1
  • 6

4 Answers4

2

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.

Farid
  • 542
  • 5
  • 16
2

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
Fahim Ahmed
  • 111
  • 7
  • 1
    i'm not new in programming but im creating my first laravel project. anyways im not quite sure in which file i should be adding the code above. so which is the file where i need to add that? – youHaveAlsoBeenABeginner Jun 20 '22 at 22:21
1

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>
0

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