Notification message popup using toastr JS plugin in Laravel
Now we can show a notification popup by adding the toastr js plugin. This plugin is used to provide notification of warning message, info message, error message, success message, etc. Using this, we are able to add a notification with an impressive layout. In order to show notification, Laravel also has a lot of packages, but in our below application, we will use the toastr JS plugin. In order to show the notification, we will add the code of toastr jQuery. After that, we are able to manage it using the session. The implementation and use of toastr JS plugin are described in the below example, and it is very easy to use. In order to add a notification, we have to follow some steps, which are described as follows:
In this step, we are going to Create New Route. This new route will be used to test toastr notifications like this:
In this step, we are going to Add Controller method. We will create HomeController as a new controller. After this, we will add the following code into it like this:
In this step, we are going to Create Notification file for Layout. We will create notification-check.blade.php file as a new file for layout. Now we will use our resource directory to create this file.
In this step, we are going to Display toastr.js notification. For this, we will create a file named notification.blade.php, which will be useful to show toastr.js notification. We will add this file to our default file so that we don’t need to write the same code everywhere. For this, we will use the notification.blade.php file. So we will add the following code into it like this:
Now our above code is ready to run. When we run this code, any of the following message popup will be generated as an output on the basis of our action: