ryancco / laravel-sessions
The missing model for Laravel sessions
Requires
- php: ^7.2
- jenssegers/agent: ^2.6
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0
- phpunit/phpunit: ^8.4|^9.0
This package is auto-updated.
Last update: 2024-10-29 23:35:41 UTC
README
The missing model for Laravel sessions with some conveniently opinionated functionality built-in.
Installation
Laravel Sessions can be installed via Composer.
composer require ryancco/laravel-sessions
Usage
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)
$user->sessions() ->active(30) // active in the last 30 minutes ->get();
Get a user's inactive sessions
@method inactive(Carbon|int $last_activity = 60)
$user->sessions()->inactive( now()->subHours(2) // not active in the last 2 hours )->get();
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() ->latest('last_activity') ->first() ->device(); $device->device(); $device->browser(); $device->platform(); $device->browserVersion(); $device->platformVersion();
Preqrequisites
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.
Contributing
Please report any problems by creating an issue. Pull requests are always welcomed.