My logout link is not working from the navigation bar; however, if I add the link on the home page, or if I go directly to the route (http://localhost/dico/public/logout) it works and the user is logged out.
When I review the page source code, I confirmed the href in the logout link is correct. If I click on the link from the source code, the user gets logged out.
ROUTE
Route::get('logout', 'SessionsController@destroy');
CONTROLLER
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SessionsController extends Controller
{
public function __construct()
{...}
public function create()
{...}
public function store()
{...}
public function destroy()
{
auth()->logout();
return redirect('/login');
}
}
THE VIEW
<li><a href="{{ URL::to('logout') }}"><i class="fa fa-sign-out fa-fw"></i> Logout</a></li>
I also tried
Logout <a style="color: #2F4F4F" href="{{ url('/logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout <i class="fa fa-sign-out pull-right" aria-hidden="true"></i>
</a>
<form id="logout-form" action="{{ url('/logout') }}" method="POST"
style="display: none;">
{{ csrf_field() }}
</form>
</li>
Try to use this intead
public function destroy()
{
Auth::logout();
return redirect('/login');
}
in controller
use Auth;
This may be helpful for you:
Need to change
<li><a href="{{ URL::to('logout') }}"><i class="fa fa-sign-out fa-fw"></i> Logout</a></li>
TO
<li><a href="{{ url('logout') }}"><i class="fa fa-sign-out fa-fw"></i> Logout</a></li>
OR
<a href="{{ url('logout') }}">LOGOUT</a>