Reputation: 677
Everyone thanks. I fixed this problem. The source of the problem;
<a class="dropdown-item" href="{{ Auth::logout() }}">Çıkış Yap</a>
this code line. Auth::logout() function. nobody clicks but this works. I will use the route.
I am using Laravel 7 library. I log in from the login page and go to the home page. However, when I refresh the page, it seems that the session has ended.
Because I use @auth and @guest in blade template. For the menu layout.
LoginController page;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = RouteServiceProvider::HOME;
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
HomeController
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('home');
}
web.php
Auth::routes();
Route::get('/', 'HomeController@index')->name('home');
and this layout.app.blade page
@guest
<a class="dropdown-item" href="{{ route('login') }}">Giriş Yap</a>
<a class="dropdown-item" href="{{ route('register') }}">Hizmet Ver</a>
@endguest
@auth
<a class="dropdown-item" href="#">Profilim</a>
<a class="dropdown-item" href="{{ Auth::logout() }}">Çıkış Yap</a>
@endauth
I hope you understand what I mean. I am logging in, yes the menu works correctly. But when the page is refreshed, it appears to be logged out.
Upvotes: 0
Views: 2137
Reputation: 521
You are calling Auth::logout()
in href
in second <a>
tag at @auth
block. When each time the page is refreshed, Auth::logout()
is called and it is logging out from current session.
Please remove the Auth::logout()
from there and add the logout URL. It will work.
@auth
<a class="dropdown-item" href="#">Profilim</a>
<a class="dropdown-item" href="{{ route('logout') }}">Çıkış Yap</a>
@endauth
Upvotes: 1