zepfietje/laravel-seeable

This package is abandoned and no longer maintained. No replacement package was suggested.

Keep track of the date and time a user was last seen.

0.3.3 2023-02-14 12:13 UTC

This package is auto-updated.

Last update: 2023-06-16 18:53:48 UTC


README

Packagist Version Packagist Downloads

Laravel Seeable

This package makes it easy to keep track of the date and time a user was last seen.

Installation

  1. Install this package:
    composer require zepfietje/laravel-seeable
  2. Optionally publish the configuration file:
    php artisan vendor:publish --tag="seeable-config"
  3. 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();
            });
        }
    
        // ...
    };
  4. Add the Seeable concern to your user model:
    namespace App\Models;
    
    // ...
    use ZepFietje\Seeable\Concerns\Seeable;
    
    class User extends Authenticatable
    {
        // ...
        use Seeable;
    }
  5. Register the SeeUser middleware in your app/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();