The missing model for Laravel sessions

0.1 2020-04-26 05:23 UTC


Packagist GitHub Workflow Status Packagist

The missing model for Laravel sessions with some conveniently opinionated functionality built-in.


Laravel Sessions can be installed via Composer.

composer require ryancco/laravel-sessions


Apply the HasSessions trait to your User model

class User extends Authenticatable
    use \Ryancco\Sessions\HasSessions;

Get a user's active sessions

@method active(Carbon|int $last_activity = 60)

    ->active(30) // active in the last 30 minutes

Get a user's inactive sessions

@method inactive(Carbon|int $last_activity = 60)

    now()->subHours(2) // not active in the last 2 hours

Get a session's device

Currently, this package leverages jenssegers/agent for device information. Check out the pieces used and head over to that repository for any further information.

$device = $user->sessions()



Laravel Sessions expects you to be using Laravel's database session driver. To learn more about this and other session driver preqrequisites, check out the documentation.


Please report any problems by creating an issue. Pull requests are always welcomed.