PHP code example of joseforozco / filament-auto-logout
1. Go to this page and download the library: Download joseforozco/filament-auto-logout 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/ */
joseforozco / filament-auto-logout example snippets
use Carbon\Carbon;
use Filament\View\PanelsRenderHook;
return [
// Habilitar o deshabilitar el plugin
'enabled' => env('FILAMENT_AUTO_LOGOUT_ENABLED', true),
// Tiempo de inactividad en segundos antes de cerrar sesión (por defecto: 15 minutos)
'duration_in_seconds' => env('FILAMENT_AUTO_LOGOUT_DURATION_IN_SECONDS', Carbon::SECONDS_PER_MINUTE * 15),
// Segundos antes del cierre de sesión en los que se muestra la advertencia
'warn_before_in_seconds' => env('FILAMENT_AUTO_LOGOUT_WARN_BEFORE_IN_SECONDS', 30),
// Mostrar el contador de tiempo restante en el panel
'show_time_left' => env('FILAMENT_AUTO_LOGOUT_SHOW_TIME_LEFT', true),
// Texto que aparece antes del contador
'time_left_text' => env('FILAMENT_AUTO_LOGOUT_TIME_LEFT_TEXT', 'Time left:'),
// Ubicación del badge dentro del panel
'location' => env('FILAMENT_AUTO_LOGOUT_LOCATION', PanelsRenderHook::GLOBAL_SEARCH_BEFORE),
];
use Joseforozco\FilamentAutoLogout\AutoLogoutPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
AutoLogoutPlugin::make(),
]);
}
use Carbon\Carbon;
use Filament\Support\Colors\Color;
use Joseforozco\FilamentAutoLogout\AutoLogoutPlugin;
->plugins([
AutoLogoutPlugin::make()
->color(Color::Emerald) // Color del badge (por defecto: Color::Stone)
->icon('heroicon-o-arrow-right-start-on-rectangle') // Ícono del badge (por defecto: heroicon-o-clock)
->logoutAfter(Carbon::SECONDS_PER_MINUTE * 5) // Cerrar sesión tras 5 minutos de inactividad
->warnBefore(60) // Advertir 60 segundos antes
->withoutWarning() // Deshabilitar la notificación de advertencia
->withoutTimeLeft() // Ocultar el contador de tiempo
->timeLeftText('Tiempo restante:') // Personalizar el texto del contador
->disableIf(fn () => auth()->id() === 1) // Deshabilitar para el usuario con ID 1
->enableIf(fn () => auth()->user()->hasRole('admin')) // Habilitar solo para admins
])