Laravel 8 Toastr Notifications Example

Websolutionstuff | Oct-19-2020 | Categories : Laravel PHP jQuery

Today, I will show you Laravel 8 Toastr Notifications Example.

There are many types of notifications available to display different messages in laravel 8 or php like display messages using bootstrap modal, simple pop-up notifications using jquery, display notifications using flash message, and toastr message notifications. So, in this post, I will show you how to add toastr notifications in laravel 8 and how to add custom messages in toastr.

So, let's see how to add toastr notification laravel 8, how to install toastr notification in laravel 8.

First, you need to add bootstrap CSS, toastr notification jquery, toastr CSS and toastr js in your main view blade file, I have added the below CDN in the <head> tag.

<head>
    <title>Laravel 8 Toastr Notification Example - websolutionstuff.com</title>

    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0- 
     alpha/css/bootstrap.css" rel="stylesheet">
	
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

	<link rel="stylesheet" type="text/css" 
     href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
	
    <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
</head>

 

 

Then after we will add differents toastr message in script tag like below.

<script>
  @if(Session::has('message'))
  toastr.options =
  {
  	"closeButton" : true,
  	"progressBar" : true
  }
  		toastr.success("{{ session('message') }}");
  @endif

  @if(Session::has('error'))
  toastr.options =
  {
  	"closeButton" : true,
  	"progressBar" : true
  }
  		toastr.error("{{ session('error') }}");
  @endif

  @if(Session::has('info'))
  toastr.options =
  {
  	"closeButton" : true,
  	"progressBar" : true
  }
  		toastr.info("{{ session('info') }}");
  @endif

  @if(Session::has('warning'))
  toastr.options =
  {
  	"closeButton" : true,
  	"progressBar" : true
  }
  		toastr.warning("{{ session('warning') }}");
  @endif
</script>

After that we need to display messages in the view file using the redirect URL in the controller. So, we need to add some code in the controller also. So, copy the below code in your controller.

return redirect()->route('your route name')->with('message','Data added Successfully');

return redirect()->route('your route name')->with('error','Data Deleted');

return redirect()->route('your route name')->with('Warning','Are you sure you want to delete? ');

return redirect()->route('your route name')->with('info','This is xyz information');

 

 

So, we are done with our code part for toastr notifications example In Laravel 8.

toastr_notifications_example_in_laravel_8

 


You might also like:

Recommended Post
Featured Post
How To Integrate Mailchimp API In Laravel 9
How To Integrate Mailchimp API...

In this article, we will see how to integrate mailchimp API in laravel 9. Here we will learn how we can integr...

Read More

Aug-01-2022

How To Create Stacked Bar Chart In Laravel 9 Using Highcharts
How To Create Stacked Bar Char...

In this article, we will see how to create a dynamic stacked bar chart in laravel 9 using highchart. Here, we will...

Read More

Dec-30-2022

How to Create Apexcharts Bar Chart in Laravel 11
How to Create Apexcharts Bar C...

Hello developers! In this article, we'll see how to create apexcharts bar chart in laravel 11. ApexCharts is a...

Read More

Apr-17-2024

How To Restrict User Access From IP Address In Laravel 9
How To Restrict User Access Fr...

Imagine this: You've made a super cool website, and now you want to make sure only the right people can use it. That...

Read More

Jan-03-2023