php-flasher / php-flasher
The core repository for PHPFlasher, hosting the source code, contributions, issue tracking, and discussions for the PHPFlasher project. This mono-repo serves as the hub for development and community engagement.
Fund package maintenance!
yoeunes
Installs: 3 404
Dependents: 0
Suggesters: 0
Security: 0
Stars: 307
Watchers: 2
Forks: 20
Open Issues: 5
Requires
- php: >=8.2
- ext-intl: *
- illuminate/contracts: ^11.0|^12.0
- illuminate/routing: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
- laravel/octane: ^2.3
- livewire/livewire: ^3.0
- paragonie/random_compat: ^2.0
- psr/container: ^1.1|^2.0
- symfony/config: ^7.0
- symfony/console: ^7.0
- symfony/dependency-injection: ^7.0
- symfony/framework-bundle: ^7.0
- symfony/http-kernel: ^7.0
- symfony/translation: ^7.0
- symfony/twig-bundle: ^7.0
- symfony/ux-twig-component: ^2.19
Requires (Dev)
- larastan/larastan: ^2.9.9
- mockery/mockery: ^1.6.12
- orchestra/testbench: ^9.5.2
- overtrue/phplint: ^9.5.3
- php-cs-fixer/shim: ^3.64.0
- phpstan/phpstan: ^1.12.7
- phpstan/phpstan-mockery: ^1.1.3
- phpstan/phpstan-phpunit: ^1.4.0
- phpstan/phpstan-symfony: ^1.4.10
- phpunit/phpunit: ^10.5.26
- rector/rector: ^1.2.8
- rector/swiss-knife: ^1.0.0
- spatie/ray: ^1.41.2
- symplify/monorepo-builder: ^11.2.22
- 2.x-dev
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- 1.x-dev
- v1.15.14
- v1.15.13
- v1.15.12
- v1.15.11
- v1.15.10
- v1.15.9
- v1.15.8
- v1.15.7
- v1.15.6
- v1.15.5
- v1.15.4
- v1.15.3
- v1.15.2
- v1.15.1
- v1.15.0
- v1.14.1
- v1.14.0
- v1.13.1
- v1.13.0
- v1.12.1
- v1.12.0
- v1.11.0
- v1.10.6
- v1.10.5
- v1.10.4
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.2
- v1.9.1
- v1.9.0
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.17
- v0.4.16
- v0.4.15
- v0.4.14
- v0.4.13
- v0.4.12
- v0.4.11
- v0.4.10
- v0.4.9
- v0.4.8
- v0.4.7
- v0.4.6
- v0.4.5
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.18
- v0.1.17
- v0.1.16
- v0.1.15
- v0.1.14
- v0.1.13
- v0.1.12
- v0.1.11
- v0.1.10
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
This package is auto-updated.
Last update: 2025-04-30 08:03:36 UTC
README
PHPFlasher: Beautiful Notifications Made Simple
π See It In Action
// In your controller public function updateProfile(Request $request) { // Process form submission $user = Auth::user(); $user->update($request->validated()); // Show a beautiful notification to the user flash()->success('Your profile has been updated successfully!'); return redirect()->back(); }
That's it! PHPFlasher will display an elegant success notification to your user. No JavaScript to write, no frontend setup needed.
π Compatibility
Requirements | Version |
---|---|
PHP | β₯ 8.2 |
Laravel | β₯ 11.0 |
Symfony | β₯ 7.0 |
π Table of Contents
- Introduction
- Features
- Installation
- Usage Examples
- Themes
- Adapters
- Advanced Configuration
- Adapter Documentation Example
- Community & Support
- Contributors
- License
π Introduction
PHPFlasher is a powerful, framework-agnostic library that makes it simple to add beautiful flash messages to your web applications. It provides a consistent API for displaying notifications across your PHP applications, whether you're using Laravel, Symfony, or any other PHP framework.
Flash messages are short-lived notifications that appear after a user performs an action, such as submitting a form. PHPFlasher helps you create these notifications with minimal effort while ensuring they look great and behave consistently.
β¨ Key Features
- Zero JavaScript Required: Write only PHP code - frontend functionality is handled automatically
- Framework Support: First-class Laravel and Symfony integration
- Beautiful Themes: Multiple built-in themes ready to use out of the box
- Multiple Notification Types: Success, error, warning, and info notifications
- Highly Customizable: Positions, timeouts, animations, and more
- Third-Party Adapters: Integration with popular libraries like Toastr, SweetAlert, and more
- API Response Support: Works with AJAX and API responses
- TypeScript Support: Full TypeScript definitions for frontend customization
- Lightweight: Minimal performance impact
π¦ Installation
For Laravel Projects
# Install the Laravel adapter composer require php-flasher/flasher-laravel # Set up assets automatically php artisan flasher:install
PHPFlasher automatically injects the necessary JavaScript and CSS assets into your Blade templates. No additional setup required!
For Symfony Projects
# Install the Symfony adapter composer require php-flasher/flasher-symfony # Set up assets automatically php bin/console flasher:install
PHPFlasher automatically injects the necessary JavaScript and CSS assets into your Twig templates.
π Usage Examples
Basic Notifications
// Success notification flash()->success('Operation completed successfully!'); // Error notification flash()->error('An error occurred. Please try again.'); // Info notification flash()->info('Your account will expire in 10 days.'); // Warning notification flash()->warning('Please backup your data before continuing.');
With Custom Titles
flash()->success('Your changes have been saved!', 'Update Successful'); flash()->error('Unable to connect to the server.', 'Connection Error');
With Custom Options
flash()->success('Profile updated successfully!', [ 'timeout' => 10000, // Display for 10 seconds 'position' => 'bottom-right', 'closeButton' => true, ]); flash()->error('Failed to submit form.', 'Error', [ 'timeout' => 0, // No timeout (stay until dismissed) 'position' => 'center', ]);
In Controllers
// Laravel public function store(Request $request) { // Process form... flash()->success('Product created successfully!'); return redirect()->route('products.index'); } // Symfony public function store(Request $request, FlasherInterface $flasher) { // Process form... $flasher->success('Product created successfully!'); return $this->redirectToRoute('products.index'); }
Specific Use Cases
// Form validation errors if ($validator->fails()) { flash()->error('Please fix the errors in your form.'); return redirect()->back()->withErrors($validator); } // Multi-step process flash()->success('Step 1 completed!'); flash()->info('Please complete step 2.'); // With HTML content (must enable HTML option) flash()->success('Your <strong>account</strong> is ready!', [ 'escapeHtml' => false ]);
π¨ Themes
PHPFlasher comes with beautiful built-in themes ready to use immediately:
Default Theme (Flasher)
The default theme provides clean, elegant notifications that work well in any application:
flash()->success('Operation completed!');
Other Built-In Themes
PHPFlasher includes multiple themes to match your application's design:
// Set the theme in your configuration or per notification flash()->success('Operation completed!', [ 'theme' => 'amazon' // Amazon-inspired theme ]); // Other available themes: // - amber: Warm amber styling // - aurora: Subtle gradient effects // - crystal: Clean, transparent design // - emerald: Green-focused modern look // - facebook: Facebook notification style // - google: Google Material Design inspired // - ios: iOS notification style // - jade: Soft jade color palette // - material: Material Design implementation // - minimal: Extremely clean and simple // - neon: Bright, attention-grabbing // - onyx: Dark mode sleek design // - ruby: Bold ruby red accents // - sapphire: Blue-focused elegant style // - slack: Slack-inspired notifications
Theme Configuration
You can configure theme defaults in your configuration file:
// Laravel: config/flasher.php return [ 'themes' => [ 'flasher' => [ 'options' => [ 'timeout' => 5000, 'position' => 'top-right', ], ], 'amazon' => [ 'options' => [ 'timeout' => 3000, 'position' => 'bottom-right', ], ], ], ];
π§© Adapters
Beyond PHPFlasher's built-in themes, you can use third-party notification libraries:
Available Adapters
Toastr
composer require php-flasher/flasher-toastr-laravel # For Laravel composer require php-flasher/flasher-toastr-symfony # For Symfony
flash('toastr')->success('Message with Toastr!');
SweetAlert
composer require php-flasher/flasher-sweetalert-laravel # For Laravel composer require php-flasher/flasher-sweetalert-symfony # For Symfony
flash('sweetalert')->success('Message with SweetAlert!');
Noty
composer require php-flasher/flasher-noty-laravel # For Laravel composer require php-flasher/flasher-noty-symfony # For Symfony
flash('noty')->success('Message with Noty!');
Notyf
composer require php-flasher/flasher-notyf-laravel # For Laravel composer require php-flasher/flasher-notyf-symfony # For Symfony
flash('notyf')->success('Message with Notyf!');
βοΈ Advanced Configuration
Laravel Configuration
Publish and customize the configuration:
php artisan vendor:publish --tag=flasher-config
This creates config/flasher.php
where you can configure:
return [ // Default adapter to use 'default' => 'flasher', // Theme configuration 'themes' => [ 'flasher' => [ 'options' => [ 'timeout' => 5000, 'position' => 'top-right', ], ], ], // Auto-convert Laravel session flash messages 'auto_create_from_session' => true, // Automatically render notifications 'auto_render' => true, // Type mappings for Laravel notifications 'types_mapping' => [ 'success' => 'success', 'error' => 'error', 'warning' => 'warning', 'info' => 'info', ], ];
Symfony Configuration
Create or edit config/packages/flasher.yaml
:
flasher: default: flasher themes: flasher: options: timeout: 5000 position: top-right auto_create_from_session: true auto_render: true types_mapping: success: success error: error warning: warning info: info
Notification Options
Common options you can customize:
flash()->success('Message', [ // Display duration in milliseconds (0 = until dismissed) 'timeout' => 5000, // Notification position 'position' => 'top-right', // top-right, top-left, bottom-right, bottom-left, top-center, bottom-center // Display a close button 'closeButton' => true, // Show progress bar during timeout 'progressBar' => true, // Right-to-left text direction 'rtl' => false, // Allow HTML content in notifications 'escapeHtml' => false, // Custom CSS class 'class' => 'my-custom-notification', ]);
π Adapter Documentation Example
Here's a detailed example of using the Toastr adapter with PHPFlasher:
Installation
composer require php-flasher/flasher-toastr
For Laravel:
composer require php-flasher/flasher-toastr-laravel
For Symfony:
composer require php-flasher/flasher-toastr-symfony
Usage
Basic Usage
use Flasher\Toastr\Prime\ToastrFactory; // Inject the factory public function __construct(private ToastrFactory $toastr) { } public function index() { $this->toastr->success('Toastr is working!'); // Or using the global helper with the specified adapter flash('toastr')->success('Toastr is awesome!'); }
With Options
flash('toastr')->success('Success message', 'Success Title', [ 'timeOut' => 5000, 'closeButton' => true, 'newestOnTop' => true, 'progressBar' => true, 'positionClass' => 'toast-top-right', ]);
Available Methods
// Standard notification types flash('toastr')->success('Success message'); flash('toastr')->info('Information message'); flash('toastr')->warning('Warning message'); flash('toastr')->error('Error message'); // Custom notification flash('toastr')->flash('custom-type', 'Custom message');
Toastr Specific Options
Option | Type | Default | Description |
---|---|---|---|
closeButton | Boolean | false | Display a close button |
closeClass | String | 'toast-close-button' | CSS class for close button |
newestOnTop | Boolean | true | Add notifications to the top of the stack |
progressBar | Boolean | true | Display progress bar |
positionClass | String | 'toast-top-right' | Position of the notification |
preventDuplicates | Boolean | false | Prevent duplicates |
showDuration | Number | 300 | Show animation duration in ms |
hideDuration | Number | 1000 | Hide animation duration in ms |
timeOut | Number | 5000 | Auto-close duration (0 = disable) |
extendedTimeOut | Number | 1000 | Duration after hover |
showEasing | String | 'swing' | Show animation easing |
hideEasing | String | 'linear' | Hide animation easing |
showMethod | String | 'fadeIn' | Show animation method |
hideMethod | String | 'fadeOut' | Hide animation method |
Advanced Configuration
Laravel Configuration
Publish the configuration file:
php artisan vendor:publish --tag=flasher-toastr-config
Symfony Configuration
Edit your config/packages/flasher.yaml
:
flasher: toastr: options: timeOut: 5000 progressBar: true
Learn More
For additional information, see the PHPFlasher documentation.
π₯ Community & Support
Getting Help
- Documentation: Visit https://php-flasher.io
- GitHub Issues: Report bugs or request features
- Stack Overflow: Ask questions with the
php-flasher
tag
Common Use Cases
- Form submission feedback
- AJAX request notifications
- Authentication messages
- Error reporting
- Success confirmations
- System alerts
π Contributors and Sponsors
Join our team of contributors and make a lasting impact on our project!
We are always looking for passionate individuals who want to contribute their skills and ideas. Whether you're a developer, designer, or simply have a great idea, we welcome your participation and collaboration.
Shining stars of our community:
Younes ENNAJI π» π π§ |
Salma Mourad π΅ |
Nashwan Abdullah π΅ |
Arvid de Jong π΅ |
Ash Allen π¨ |
Tony Murray π» |
StΓ©phane P π |
Lucas Maciel π¨ |
Ahmed Gamal π» π |
Brooke. π |
π¬ Contact
PHPFlasher is being actively developed by yoeunes. You can reach out with questions, bug reports, or feature requests on any of the following:
π License
PHPFlasher is open-sourced software licensed under the MIT license.
Made with β€οΈ by Younes ENNAJI