This Laravel tutorial helps to add notification functionality to Laravel 10. I am using flasher-laravel and with popular notification toaster library.
Toastr is an awesome JavaScript library that helps to display messages in the form of notifications, the message could be the type of info, success, warning, or error.
The only dependency is jQuery and flasher-laravel libs, it’s running into the top of the jQuery libs. I am using third-party laravel package to display message into the application.
This Laravel flasher package helps you to add notifications to your Laravel 10 project.
You can also check other recommended tutorials of Lumen/Laravel,
- How to Monitor Beanstalkd Queue In Laravel Using Admin Console
- How to Configure supervisord on Linux for Laravel Jobs Queue
- Laravel Micro Rest Framework – Simple Example of RESTful API in Lumen
- How to Configure Memcached in Lumen Api Framework
- Simple Example of Laravel 5 Login System Using Sentry
- Authorization and Authentication of Users in laravel 5 Using Sentry
- Simple Laravel Layouts using Blade Template and Bootstrap Theme
What’s PHPFlasher Library
You can add flash messages to your Laravel or Symfony projects quickly and simply with PHPFlasher, a robust and user-friendly package. Flash messages are an easy and efficient way to give feedback to your users, whether you need to notify them of a successful form submission, an error, or any other important information.
PHPFlasher supports popular notification libraries : toastr.js, sweetalert 2, pnotify, noty, notyf and even show desktop notifications.
The other features are:
- Display multiple notifications at the same time
- Easily display notifications from JavaScript with a small footprint
- LTR and Dark-mode support
- Show Desktop notifications for : Linux, macOS, Windows
- Framework-agnostic with Laravel and Symfony implementations
- PHPSTORM Autocomplete
- You can always create an adapter yourself if desired
Integrate PHPFlasher with Laravel
You can use it directly toaster.js
lib’s into Laravel application but that needs more configurations. The Laravel PHPFlasher package is easy to use and integrates with the Laravel application. This is a simple plug-and-play plugin.
Install PHPFlasher And additional Adapter Toaster
Install the PHPFlasher package using composer.
composer require php-flasher/flasher-laravel
install the toaster adapter in our Laravel application.
$laravel_project> require php-flasher/flasher-toastr-laravel
How To Use Toaster in Laravel
Let’s call toaster method into the controller file.
namespace App\Controller; class AppController { public function save() { toastr()->addSuccess('Your account has been restored.'); } }
Notification With Close Button
You can also set the value true
into the closeButton()
method, a close button is displayed in the toast notification.
toastr() ->closeButton(true) ->addWarning('Your password may be at risk.');
Thanks @Parvez for ths tutorial, after reading your tutorial I released a new version 1.1.0 that support Lumen.
Thanks for lovely package 🙂
Hello this library is abandoned, please use “php-flasher/flasher-laravel” instead
thanks