Notification Example Using Laravel 10

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,

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.jssweetalert 2pnotifynotynotyf 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.');

4 thoughts on “Notification Example Using Laravel 10

Leave a Reply

Your email address will not be published. Required fields are marked *