Laravel PWA is a package designed to seamlessly integrate Progressive Web Application (PWA) functionality into your Laravel projects. With this package, you can easily configure, update the manifest, and register service workers, enabling any Laravel app to function as a PWA.
- Automatically generate PWA manifest and service worker
- Configurable installation button
- Supports Laravel 8, 9, 10, and 11
- Easy setup and usage
- Compatible with mobile and desktop devices
Note: PWAs require a secure HTTPS connection to work correctly. Ensure your application is hosted with HTTPS; otherwise, service workers and other PWA features will not function as expected.
To get started, install the package using Composer:
composer require erag/laravel-pwa
Once installed, publish the PWA configuration files using:
php artisan erag:publish-laravel-pwa
This will create the required configuration file config/pwa.php
and set up PWA functionality for your application.
This is your main configuration file where you can customize the PWA settings.
return [
'install-button' => true, // Show or hide install button globally
'manifest' => [
'name' => 'Laravel PWA',
'short_name' => 'LPT',
'background_color' => '#6777ef',
'display' => 'fullscreen',
'description' => 'A Progressive Web Application setup for Laravel projects.',
'theme_color' => '#6777ef',
'icons' => [
[
'src' => 'logo.png',
'sizes' => '512x512',
'type' => 'image/png',
],
],
],
'debug' => env('APP_DEBUG', false),
];
After changing config/pwa.php
in your manifest
array, run this command
You can update your PWA manifest file by running:
php artisan erag:pwa-update-manifest
This command updates the manifest.json
file located in the public directory of your Laravel project.
To integrate PWA functionality into your layouts, use the provided Blade directives.
Place the @PwaHead
directive inside the <head>
tag of your main layout file:
<!DOCTYPE html>
<html lang="en">
<head>
@PwaHead <!-- Add this directive to include the PWA meta tags -->
<title>Your App Title</title>
</head>
<body>
Just before the closing </body>
tag in your main layout file, add:
@RegisterServiceWorkerScript <!-- This registers the service worker -->
</body>
</html>
These directives will automatically generate the necessary tags and JavaScript for the PWA.
We appreciate your interest in contributing to this Laravel PWA project! Whether you're reporting issues, fixing bugs, or adding new features, your help is greatly appreciated.
-
Go to the repository page on GitHub.
-
Click the Fork button at the top-right corner of the repository page.
-
Clone your forked repository:
git clone https://github.com/your-username/laravel-pwa.git
If you encounter any issues, please check if the issue already exists in the Issues section. If not, create a new issue with the following details:
- Steps to reproduce the issue
- Expected and actual behavior
- Laravel version
- Any relevant logs or screenshots
When you're ready to contribute, open a pull request describing the changes you’ve made and how they improve the project. Please ensure:
- All commits are squashed into one clean commit.
- The code follows PSR-12 standards.
- You’ve tested the changes locally.
- Follow the PSR-12 PHP coding standards.
- Keep your commit history clean and meaningful.
- Add comments where needed but avoid over-commenting.
Here’s a simple example of how to use this package:
- Install the package via Composer.
- Publish the configuration files.
- Add the
@PwaHead
directive in your layout file’s<head>
. - Add the
@RegisterServiceWorkerScript
directive before the closing</body>
tag. - Customize the
config/pwa.php
to fit your project’s needs. - Run
php artisan erag:pwa-update-manifest
to update the manifest file. - That's it! Your Laravel app is now PWA-enabled. 🚀