skip to Main Content

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

2

Answers


  1. 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

    Hope this helps

    Login or Signup to reply.
  2. use logout route

     <form method="POST" action="{{ route('logout') }}">
          @csrf
          <button type="submit">Logout</button>
     </form>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search