Installation
composer require alareqi/filament-pwa
For Filament v4:
filament-pwa install
For Filament v3:
filament-pwa install --v3
Publish Config & Assets
php artisan vendor:publish --provider="AlaReqi\FilamentPWA\FilamentPWAFacadeServiceProvider" --tag="filament-pwa-config"
php artisan vendor:publish --provider="AlaReqi\FilamentPWA\FilamentPWAFacadeServiceProvider" --tag="filament-pwa-assets"
Register Plugin
Add to app/Providers/Filament/AdminPanelProvider.php (v3) or bootstrap/app.php (v4):
// v4
->plugin(AlaReqi\FilamentPWA\FilamentPWAPlugin::make())
First Use Case Visit your Filament admin panel. The PWA prompt will appear automatically after 3 seconds (configurable). Test offline mode by:
// config/filament-pwa.php
return [
'manifest' => [
'name' => 'My Admin Panel',
'short_name' => 'Admin',
'theme_color' => '#2d3748',
'background_color' => '#ffffff',
'display' => 'standalone', // 'fullscreen', 'minimal-ui', 'standalone'
'icons' => [
[
'src' => 'icons/icon-72x72.png',
'sizes' => '72x72',
'type' => 'image/png',
],
// Add more sizes (192x192, 512x512)
],
],
'install_prompt' => [
'enabled' => true,
'delay' => 3, // seconds
'ios_message' => 'Add to Home Screen for quick access',
'android_message' => 'Install for offline access',
],
];
Use the generateIcons Artisan command to create icons from a source image:
php artisan filament-pwa:generate-icons --source=public/images/logo.png --output=public/icons
Supports multiple sizes (72x72, 120x120, 144x144, 152x152, 192x192, 384x384, 512x512).
The service worker (filament-pwa-sw.js) automatically caches:
cache_strategy)offline_routes config)'offline_routes' => [
'api/admin/resources',
'api/admin/settings',
],
Translate prompts and messages via resources/lang:
// resources/lang/en/pwa.php
return [
'install_prompt' => [
'title' => 'Install My Admin',
'description' => 'Click the install button to use this app offline',
],
];
Extend the default service worker by publishing the template:
php artisan vendor:publish --provider="AlaReqi\FilamentPWA\FilamentPWAFacadeServiceProvider" --tag="filament-pwa-sw"
Then modify resources/js/filament-pwa-sw.js:
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('filament-pwa-cache').then((cache) => {
// Custom cache logic
})
);
});
offline_routes config to cache critical API endpoints.'offline_routes' => [
'api/admin/resources/{resource}',
'api/admin/resources/{resource}/{id}',
],
vite.config.js:
export default defineConfig({
build: {
rollupOptions: {
output: {
manualChunks: (id) => {
if (id.includes('node_modules')) {
return 'vendor';
}
},
},
},
},
});
use AlaReqi\FilamentPWA\Facades\FilamentPWA;
FilamentPWA::addNotification(
title: 'Offline Mode',
message: 'You are now working offline. Changes will sync when connection is restored.',
type: 'info'
);
cache_strategy to control cache behavior:
'cache_strategy' => 'network-first', // 'cache-first', 'network-only'
beforeinstallprompt events in some contexts.standalone display mode and ensure your manifest is properly configured:
'manifest' => [
'display' => 'standalone',
'apple' => [
'status_bar_style' => 'black-translucent',
],
],
localhost.http://localhost for testing or configure your dev environment with HTTPS.// config/app.php
'assets_version' => 'v1.0',
F12).filament-pwa-sw.js registration.Application → Service Workers → Offline).Update on reload.start_url.display mode.Listen for PWA events in your JavaScript:
document.addEventListener('filament-pwa:installed', (event) => {
console.log('PWA installed!', event.detail);
});
document.addEventListener('filament-pwa:offline', () => {
// Show offline notification
});
Use the Facade to trigger actions:
use AlaReqi\FilamentPWA\Facades\FilamentPWA;
// Check if PWA is installed
if (FilamentPWA::isInstalled()) {
// ...
}
// Show install prompt manually
FilamentPWA::showInstallPrompt();
Override the default service worker registration:
// resources/js/filament-pwa.js
window.addEventListener('load', () => {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/custom-sw.js')
.then((registration) => {
console.log('Custom SW registered:', registration);
})
.catch((error) => {
console.error('SW registration failed:', error);
});
}
});
Load PWA config dynamically based on user roles:
FilamentPWA::configure(function ($config) {
if (auth()->user()->is_admin) {
$config->manifest['display'] = 'fullscreen';
}
});
How can I help you explore Laravel packages today?