Olipol
Olipol

Reputation: 315

Check if session has expired in Laravel 5.4

How do I check if the session has expired in laravel 5.4.

If the session has expired I want to show a message.

Upvotes: 4

Views: 7445

Answers (2)

Adarsh Sojitra
Adarsh Sojitra

Reputation: 2199

Laravel will Create Session For every user no matter the User is Logged in or not. It will create Token for Specific Session. You can check if the Token Exist or not.

You can check if the token is there or not by the function Session::get('_token');.

But if you are asking if You want to check if User's Session is Expired, You can use Auth::check(). It will return if the Session is Expired or not for the specific user.

For example, If the user is Logged in, It will return True or False. But you can't check if overall Session is Expired or not Because Laravel will create and Store Session For every Single Visit No Matter if the user is Authenticated or not.

Let me know if you have any More Questions or Queries regarding Laravel Sessions. Let me know if it Helps!

Upvotes: 1

prola
prola

Reputation: 2823

You can use the following

if(Auth::check()) { 

}

Upvotes: 3

Related Questions