How to Add Toastr Notification in Laravel 11?

How to Add Toastr Notification in Laravel 11?

How to Add Toastr Notification in Laravel 11. In this article, I will explain to you how to add toastr flash notification in laravel 11 application.

Toastr.js is a JavaScript library used to display small, non-blocking notifications or alerts on a webpage. It is lightweight and customizable, allowing developers to show messages like success, error, warning, or info with different styles. Toastr helps improve user experience by showing quick feedback.

In this example, we will create a notifications Blade file and define success, info, warning, and error flash messages. Then, we will include that notifications file in the layout so we don’t have to rewrite the same code repeatedly. When a flash message is triggered from the controller, it will pop up with a Toastr notification. Let’s go through the simple steps to get it done.

You Can Learn Laravel 11 Add Watermark on Image Tutorial

Step for How to Add Toastr Notification in Laravel 11

  • Step 1: Install Laravel 11
  • Step 2: Define Notifications
  • Step 3: Create Routes
  • Step 4: Create Controller
  • Run Laravel App:>

Step 1: Install Laravel 11

First of all, we need to get a fresh Laravel 11 version application using the command below because we are starting from scratch. So, open your terminal or command prompt and run the command below:

Step 2: Define Notifications

Here, we will create notifications blade file and define all flash messages.

we will import CDN js and css for JQuery and Toastr JS.

so, let’s create the following blade files and update it.

resources/views/demo.blade.php

resources/views/notifications.blade.php

Step 3: Create Routes

In this step, we need to create some routes for notification. So open your “routes/web.php” file and add the following route.

routes/web.php

Step 4: Create Controller

Here, we will create NotificationController controller. we will define two method on it. one will simple require view file and another will send back with flash message. so, let’s create and update it.

app/Http/Controllers/NotificationController.php

Run Laravel App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:

Now, Go to your web browser, type the given URL and view the app output:

I hope it can help you…

You Can Learn Udemy – SQL Bootcamp – Manipulate Data Like a Pro 2024

This Post Has One Comment

Leave a Reply