Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AyobamilayeY's avatar

Laravel logout is not working

The current version of laravel uses JS for logout when I'm trying to use app over a JS disabled browser its throwing some error. I know not much people disable JS but i want my project to be fully based on PHP instead.

Current code of my app.layout uses:

<li class="nav-item">
           <a class="nav-link" href="{{ route('logout') }}"
             onclick="event.preventDefault();
             document.getElementById('logout-form').submit();">
                                    {{ __('Logout') }}
           </a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
@csrf
      </form>
          </li>

I have tried the "Auth:Logout" method as href so when user click on logout it'll use Auth functions and logout but when I'm doing that app is breaking and logging out user right after logging in! i can only see one page after login and then it log out by self. Note:My version of laravel is 6.x and everything is updated.

Thanks

0 likes
1 reply
tisuchi's avatar
tisuchi
Best Answer
Level 70

@ayobamilayey

Just put the link inside the form

<li class="nav-item">
    <form id="logout-form" action="{{ route('logout') }}" method="POST">
        @csrf
        <button class="nav-link" type="submit">
            {{ __('Logout') }}
        </button>
    </form>
</li>

The style might be off this way, but you can fix it easily.

2 likes

Please or to participate in this conversation.