How to get number of session in laravel project?

Member

by addison , in category: PHP Frameworks , a year ago

How to get number of session in laravel project?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by filiberto , 7 months ago

@addison 

To get the number of sessions in a Laravel project, you can use the following code in your controller or wherever you want to display the number of sessions:

1
$numberOfSessions = count(session()->getId());


This code uses the session() helper function to get the session ID and then counts the number of sessions based on the number of unique session IDs that have been created.


You can then pass the $numberOfSessions variable to your view to display the number of sessions in your Laravel project.

Related Threads:

How to use same session on two laravel project?
How to get project or root dir in symfony 5?
How to get row number of a row in laravel?
How to count the number of data in laravel?
How to separate user session from admin session in laravel?
How to get date string from day number and month number using moment.js?