Why is Logout not working in Laravel via link?

  • 0
    Good day.

    There is Laravel latest version (^ 8) with Jetstream installed (with Alphine).

    I am trying to log out, but for some reason the following problem appears:

    There is a form with a link on which the user will have to log out of the account:
    <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                            <form method="POST" action="{{ route('logout') }}">
                                @csrf
    
                                <li>
                                    <a class="dropdown-item" href="{{ route('logout') }}" onclick="event.preventDefault(); this.closest('form').submit();">
                                        {{ __('Log out') }}
                                    </a>
                                </li>
                            </form>
                        </ul>


    But when I click on the link, the following message is displayed:
    The GET method is not supported for this route. Supported methods: POST.

    But in the form, I explicitly indicate that you need to use POST .

    But when I use a ready-made example on TailwindCSS, everything works fine:
    <form method="POST" action="{{ route('logout') }}">
                                @csrf
    
                                <x-jet-dropdown-link href="{{ route('logout') }}" onclick="event.preventDefault(); this.closest('form').submit();">
                                    {{ __('Logout') }}
                                </x-jet-dropdown-link>
                            </form>


    Could you tell me what I missed / did not take into account? Thanks in advance!

    PS: Wang, that the problem is in "onclick". But I don't know what needs to be changed.
    JavaScript Anonymous, Dec 10, 2019

  • 1 Answers
  • 0
    Try adding {{method_field ('POST')}} to the form
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!