devrabiul / laravel-pwa-kit
Laravel PWA Kit is a lightweight and flexible package to add Progressive Web App (PWA) support to your Laravel applications with ease.
Requires
- php: >=8.0
README
Laravel PWA Kit is a powerful, easy-to-use Laravel package that transforms your web applications into Progressive Web Apps (PWAs). With this package, your Laravel apps can be installable, offline-ready, fast, and engaging, without writing complex service worker logic manually.
β¨ Features
- βοΈ Automatic Manifest & Service Worker Generation β No manual setup needed.
- π² Add-to-Home-Screen Install Prompt β Fully configurable toast notification.
- π₯οΈπ± Responsive & Cross-Platform β Works on mobile, tablet, and desktop.
- π Laravel 8.x β 12.x Compatible β Supports latest Laravel versions.
- π οΈ Customizable β Modify icons, theme colors, app name, shortcuts via config.
- β‘ Offline Ready β Supports offline pages and caching strategies.
- π HTTPS Ready β Fully compatible with HTTPS-secured applications.
- π§© Livewire & SPA Friendly β Works out-of-the-box with Livewire v3, Vue 3, and React.
- π± Treeware Package β Support environmental initiatives by contributing to tree planting.
πΌοΈ Screenshots / Demo
See Laravel PWA Kit in action:
Descriptions:
- Install Toast Prompt β The prompt displayed when users can add your app to the home screen.
- Offline Page β Shown when the user is offline.
- Installed PWA β Your Laravel app running as an installable Progressive Web App.
Live Demo: https://packages.rixetbd.com/laravel-pwa-kit
β οΈ Important
PWAs require HTTPS to work correctly. Make sure your application is hosted with HTTPS; otherwise, service workers and other PWA features will not function properly.
Note: For local development, you can use
php artisan serve
. Browsers allow service workers onlocalhost
over HTTP, so you can test your PWA without HTTPS during development.
π¦ Installation
Install via Composer:
composer require devrabiul/laravel-pwa-kit
Publish configuration and assets:
php artisan vendor:publish --provider="Devrabiul\PwaKit\PwaKitServiceProvider"
This publishes:
config/laravel-pwa-kit.php
manifest.json
,sw.js
,offline.html
, andlogo.png
to both public and base directories.
βοΈ Configuration
Edit config/laravel-pwa-kit.php
to customize your PWA:
return [ 'enable_pwa' => true, 'install-toast-show' => true, 'manifest' => [ 'name' => env('APP_NAME', 'Laravel'), 'short_name' => 'LPT', 'start_url' => '/', 'theme_color' => '#FF5733', 'background_color' => '#ffffff', 'display' => 'standalone', 'icons' => [ [ 'src' => 'logo.png', 'sizes' => '512x512', 'type' => 'image/png', ] ], ], 'livewire-app' => false, ];
π₯οΈ Usage
Include Assets in Blade
In <head>
:
{!! PwaKit::head() !!}
Before </body>
:
{!! PwaKit::scripts() !!}
Example Layout:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My PWA App</title> {!! PwaKit::head() !!} </head> <body> <h1>Welcome to My PWA App</h1> {!! PwaKit::scripts() !!} </body> </html>
π² Multiple Forced Install Buttons
You can add multiple buttons anywhere in your app to force the PWA install prompt. Use the .force-install-pwa-app
class on any button and attach the install trigger:
<!-- Example Buttons --> <button class="force-install-pwa-app">Install App</button> <button class="force-install-pwa-app">Add to Home Screen</button>
// Trigger install prompt for multiple buttons document.querySelectorAll(".force-install-pwa-app").forEach((btn) => { btn.onclick = triggerPWAInstall; });
π‘ Tip:
triggerPWAInstall
is the helper function provided by Laravel PWA Kit that opens the browserβs add-to-home-screen prompt. You can place as many buttons as you want in your UI.
Livewire Support
Enable in config/laravel-pwa-kit.php
:
'livewire-app' => true,
This ensures your service worker and toast behave correctly in Livewire SPA apps.
π οΈ Major Methods & Usage
Method | Description | Example |
---|---|---|
PwaKit::head() |
Generates <meta> , <link> and stylesheet tags for PWA. |
{!! PwaKit::head() !!} |
PwaKit::scripts() |
Registers service worker, scripts, and install toast HTML. | {!! PwaKit::scripts() !!} |
PwaKit::updatePWALogo(Request $request) |
Handles logo upload, validates, and stores in public & base paths. | $result = PwaKit::updatePWALogo($request); |
createOrUpdate(array $manifest, bool $force = false) |
Programmatically create or update manifest.json . |
$pwa = new PwaKit(); $pwa->createOrUpdate($manifest); |
update(array $manifestData) |
Updates manifest data safely. | $pwa = new PwaKit(); $pwa->update($manifestData); |
π οΈ Major Methods Usage Examples
1. PwaKit::head()
Generates all <meta>
, <link>
and stylesheet tags required for your PWA.
{{-- In the <head> section of your Blade template --}} {!! PwaKit::head() !!}
2. PwaKit::scripts()
Registers the service worker, required scripts, and displays the install toast.
{{-- Before closing </body> tag --}} {!! PwaKit::scripts() !!}
3. PwaKit::updatePWALogo(Request $request)
Handles logo upload, validates dimensions and type, and stores the logo in public & base directories.
use Illuminate\Http\Request; use Devrabiul\PwaKit\Facades\PwaKit; public function updateLogo(Request $request) { $result = PwaKit::updatePWALogo($request); if ($result['status']) { return back()->with('success', $result['message']); } else { return back()->withErrors($result['errors'] ?? $result['error']); } }
4. createOrUpdate(array $manifest, bool $force = false)
Programmatically creates or updates the manifest.json
file.
use Devrabiul\PwaKit\PwaKit; $pwa = new PwaKit(); $manifest = [ 'name' => 'My Awesome PWA', 'short_name' => 'AwesomePWA', 'start_url' => '/', 'display' => 'standalone', 'background_color' => '#ffffff', 'theme_color' => '#ff5733', ]; $pwa->createOrUpdate($manifest, true); // true = force overwrite
5. update(array $manifestData)
Safely updates manifest data without overwriting other existing keys.
use Devrabiul\PwaKit\PwaKit; $pwa = new PwaKit(); $updatedManifest = [ 'theme_color' => '#00aaff', 'background_color' => '#f0f0f0', ]; $pwa->update($updatedManifest);
π‘ Benefits
- β Turn your Laravel web app into an installable PWA instantly.
- β Provides offline support, caching, and fast load times.
- β Reduces repetitive boilerplate code for service workers & manifest.
- β Fully customizable via configuration.
- β Works seamlessly with Blade, Livewire, Vue 3, and React.
- β Encourages modern web best practices.
π§ Commands
- Update Manifest:
php artisan pwa:update-manifest
β οΈ Requirements
- Laravel 8.x to 12.x
- PHP 8.0+
- HTTPS (PWAs require secure contexts for service workers)
- Optional: Livewire v3 for SPA support
π± Treeware
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest youβll be creating employment for local families and restoring wildlife habitats.
π€ Contributing
- Fork the repository.
- Make your changes.
- Submit a pull request.
Feature requests and bugs? Open an issue.
π License
MIT License β see LICENSE file.
π¬ Contact
For support: π§ Email: devrabiul@gmail.com π GitHub: devrabiul/laravel-pwa-kit