Search code examples
phplaravellaravel-livewirelaravel-9

Laravel Livewire logout button doesn't work


I have created a Laravel 9 application with Livewire and there I have a logout button which use Auth::logout() and redirect to the login page. I have set up everything correctly as I understand but the button doesn't work.

Function in Profile.php

public function logoutUser() {

        Auth::logout();

        return redirect(route('auth.login'));

    }

Logout button in profile.blade.php

<button wire:click="logoutUser" class="block px-4 py-2 mt-2 text-sm bg-white md:mt-0 focus:text-gray-900 hover:bg-indigo-100 focus:bg-gray-200 focus:outline-none focus:shadow-outline">Logout</button>

What is the issue here? TIA!


Solution

  • As @Qirel recommended I used a regular controller instead of a Livewire controller to handle the logout. Followed this answer for implement that correctly.