Keep track of the date and time a user was last seen.
This package makes it easy to keep track of the date and time a user was last seen.
composer require zepfietje/laravel-seeable
php artisan vendor:publish --tag="seeable-config"
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();
});
}
// ...
};
Seeable
concern to your user model:namespace App\Models;
// ...
use ZepFietje\Seeable\Concerns\Seeable;
class User extends Authenticatable
{
// ...
use Seeable;
}
SeeUser
middleware in your app/Http/Kernel.php
file:protected $middlewareGroups = [
'web' => [
// ...
\ZepFietje\Seeable\Http\Middleware\SeeUser::class,
],
];
User::seenAfter('2022-06-30')->get();
$dailyActiveUsers = User::seenPastDay()->count();
$weeklyActiveUsers = User::seenPastWeek()->count();
$monthlyActiveUsers = User::seenPastMonth()->count();