zepfietje / laravel-seeable
Keep track of the date and time a user was last seen.
Installs: 2 123
Dependents: 0
Suggesters: 0
Security: 0
Stars: 37
Watchers: 2
Forks: 4
Open Issues: 0
Requires
- php: ^8.1
- illuminate/contracts: ^9.0|^10.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- laravel/pint: ^1.1
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpunit/phpunit: ^9.5
README
Laravel Seeable
This package makes it easy to keep track of the date and time a user was last seen.
Installation
- Install this package:
composer require zepfietje/laravel-seeable
- Optionally publish the configuration file:
php artisan vendor:publish --tag="seeable-config"
- Add a
seen_at
column to your users table:return new class extends Migration { public function up(): void { Schema::table('users', function (Blueprint $table) { $table->timestamp('seen_at')->nullable(); }); } // ... };
- Add the
Seeable
concern to your user model:namespace App\Models; // ... use ZepFietje\Seeable\Concerns\Seeable; class User extends Authenticatable { // ... use Seeable; }
- Register the
SeeUser
middleware in yourapp/Http/Kernel.php
file:protected $middlewareGroups = [ 'web' => [ // ... \ZepFietje\Seeable\Http\Middleware\SeeUser::class, ], ];
Usage
Query scopes
User::seenAfter('2022-06-30')->get(); $dailyActiveUsers = User::seenPastDay()->count(); $weeklyActiveUsers = User::seenPastWeek()->count(); $monthlyActiveUsers = User::seenPastMonth()->count();