PHP code example of evanschleret / laravel-user-presence

1. Go to this page and download the library: Download evanschleret/laravel-user-presence library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

evanschleret / laravel-user-presence example snippets


use EvanSchleret\LaravelUserPresence\Traits\HasUserPresence;

class User extends Authenticatable
{
    use HasUserPresence;
}

'policy' => App\Presence\UserPresencePolicy::class,

namespace App\Presence;

use EvanSchleret\LaravelUserPresence\Contracts\PresencePolicy;
use Illuminate\Database\Eloquent\Model;

class UserPresencePolicy implements PresencePolicy
{
    public function isEnabled(Model $user): bool
    {
        return (bool) $user->getAttribute('presence_enabled');
    }
}

return [
    'store' => 'auto',
    'cache_store' => env('LARAVEL_USER_PRESENCE_CACHE_STORE'),
    'cache_prefix' => 'laravel-user-presence',
    'cache_retention' => 86400,
    'activity_write_interval' => 60,
    'online_threshold' => 300,
    'idle_threshold' => 600,
];

'guard' => 'web',
'heartbeat' => [
    'enabled' => true,
    'path' => 'user-presence/heartbeat',
    'middleware' => ['web'],
    'rate_limit' => [
        'attempts' => 60,
        'decay_minutes' => 1,
    ],
],

use EvanSchleret\LaravelUserPresence\Middleware\UpdateLastSeen;
use Illuminate\Foundation\Configuration\Middleware;

->withMiddleware(function (Middleware $middleware): void {
    $middleware->web(append: [UpdateLastSeen::class]);
})

'store' => 'column',
bash
php artisan vendor:publish --provider="EvanSchleret\LaravelUserPresence\Providers\LaravelUserPresenceServiceProvider"