Install the Package
composer require tomatophh/filament-pwa
Publish and Run Migrations
php artisan vendor:publish --provider="Spatie\LaravelSettings\LaravelSettingsServiceProvider" --tag="migrations"
php artisan migrate
php artisan filament-settings-hub:install
php artisan filament-pwa:install
Register the Plugin
Add the plugin to your AdminPanelProvider in app/Providers/Filament/AdminPanelProvider.php:
return AdminPanel::make()
->plugin(\TomatoPHP\FilamentPWA\FilamentPWAPlugin::make());
Access the PWA Settings Navigate to Filament Settings Hub → PWA Settings to configure:
Test the PWA
Application > Service Workers).Application > Service Workers > Offline).Configuration via Filament UI
Dynamic Asset Handling
manifest.json and sw.js (Service Worker) based on settings.php artisan vendor:publish --provider="TomatoPHP\FilamentPWA\FilamentPWAServiceProvider" --tag="pwa-assets"
Then modify /resources/pwa/sw.js or /resources/pwa/manifest.json.Conditional PWA Activation
FilamentPWAPlugin::make()
->canAccess(function (User $user) {
return $user->isAdmin(); // Example: Only admins get PWA
})
Asset Caching Strategy
FilamentPWAPlugin::make()
->cacheStrategy('stale-while-revalidate') // Options: 'cache-first', 'network-first'
Localization Support
FilamentPWAPlugin::make()
->translationPrefix('pwa.')
Then add translations to resources/lang/{locale}/pwa.php.AdminPanel and TenantPanel if using multi-tenancy.APP_URL with https:// in production.npm install -g lighthouse-ci
lighthouse https://your-filament-app.test --chrome-flags="--headless" --output=html --output-path=./lighthouse-report.html
Service Worker Registration Conflicts
FilamentPWAPlugin::make()
->registerServiceWorker(false)
Then manually register your own SW in resources/js/app.js:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/pwa/sw.js');
}
Caching Stale Assets
filament-pwa:clear-cache command to force a cache refresh:
php artisan filament-pwa:clear-cache
Or manually update the Service Worker version in manifest.json:
{
"name": "My Filament App",
"short_name": "Filament",
"version": "1.0.1" // Increment this to bust cache
}
Manifest.json Validation
manifest.json (e.g., missing start_url) can break PWA installation.Manifest: Line: 1, column: 1, Syntax error.
Filament Livewire Conflicts
FilamentPWAPlugin::make()
->excludeRoutes(['livewire/*', 'filament/pages/*'])
Service Worker Debugging
Application > Service Workers) and check:
install, activate, and fetch events in the SW console.workbox-recipes for advanced caching logic:
// In /resources/pwa/sw.js
import { precacheAndRoute } from 'workbox-precaching';
precacheAndRoute(self.__WB_MANIFEST);
Offline Testing
Application > Service Workers > Offline).fetch events in the SW console for cached responses.Filament Plugin Logs
'logging' => [
'channels' => [
'filament-pwa' => [
'driver' => 'single',
'path' => storage_path('logs/filament-pwa.log'),
'level' => 'debug',
],
],
],
Then add the channel to config/logging.php.Custom PWA Pages
FilamentPWAPlugin::make()
->offlinePage(function () {
return view('filament.pwa.offline');
});
Dynamic Manifest Data
// In sw.js
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('dynamic-cache').then((cache) => {
return fetch('/api/pwa/dynamic-manifest').then((response) => {
return cache.put('dynamic-manifest', response);
});
})
);
});
Push Notifications
// In a Filament resource/action
use WebPush\WebPush;
$subscription = $request->input('subscription');
WebPush::setVapidCredentials(
env('VAPID_PUBLIC_KEY'),
env('VAPID_PRIVATE_KEY'),
env('VAPID_SUBJECT')
);
WebPush::sendNotification($subscription, json_encode(['title' => 'Alert']));
FilamentPWAPlugin::make()
->usePushNotifications()
->subscriptionModel(\App\Models\PushSubscription::class);
Theming
php artisan vendor:publish --provider="TomatoPHP\FilamentPWA\FilamentPWAServiceProvider" --tag="pwa-
How can I help you explore Laravel packages today?