Looking to hire Laravel developers? Try LaraJobs

laravel-sessions maintained by ryancco

Description
The missing model for Laravel sessions
Author
Last update
2023/02/01 20:44 (dev-dependabot/composer/symfony/http-kernel-5.4.20)
License
Links
Downloads
3

Comments
comments powered by Disqus

Laravel Sessions

Packagist GitHub Workflow Status Packagist

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.