Reputation: 704
i used default laravel authentication and get user name into my form. but when i use logout it shows logout route and show error page expire .
this is my view logout code
<ul class="navbar-nav ml-auto">
<!-- Authentication Links -->
@guest
<li><a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a></li>
@else
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" 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>
</div>
</li>
@endguest
</ul>
when i click logout it shows me /logout url and it's not working. how can i fix this error and redirect to my /home path
Upvotes: 1
Views: 7309
Reputation: 1
I tried all the above and didnt work but finally did it like this and it worked!!
php artisan ui bootstrap
php artisan ui vue
php artisan ui react
php artisan ui bootstrap --auth
php artisan ui vue --auth
php artisan ui react --auth
Run all this one by one and
npm install
npm run dev
again and it will surely work
Upvotes: -1
Reputation: 13544
Just replace @csrf
by {{ csrf_field() }}
in the logout form:
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
Your problem because there is no csrf token sent with the logout form.
Upvotes: 2
Reputation: 3184
There are possibly issues with your session cookies.
This may depend on your environment but I have fixed the issue before by making sure that config/session.php
file contains this line
'domain' => env('SESSION_DOMAIN', null),
Then remove the SESSION_DOMAIN
line in your .env
file
Then composer dumpautoload
Also, check your APP_URL
in your .env
is correct.
Upvotes: 1