toastr.js notification for laravel

<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>

4.13
8
Damien 105 points

                                    //There are many types of notification available to dispaly diffrent messages in laravel or php like simple pop up notification using jquey, display messages using bootstrap modal, dispaly notification using flash message, and toastr message notification. So,let's start and add below code in your application to get output.

//first you need to add bootstrap CSS, Jquery js, toastr CSS and toastr js in you main view blade file, I have added below CDN in &lt;head&gt; tag.

 

&lt;head&gt;
    &lt;title&gt;Laravel Toastr Notification Example - websolutionstuff.com&lt;/title&gt;

    &lt;link href=&quot;https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0- 
     alpha/css/bootstrap.css&quot; rel=&quot;stylesheet&quot;&gt;
	
    &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;

	&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; 
     href=&quot;https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css&quot;&gt;
	
    &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
//Then after we need to add diffrents toastr message in script tag like below.

&lt;script&gt;
  @if(Session::has('message'))
  toastr.options =
  {
  	&quot;closeButton&quot; : true,
  	&quot;progressBar&quot; : true
  }
  		toastr.success(&quot;{{ session('message') }}&quot;);
  @endif

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

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

  @if(Session::has('warning'))
  toastr.options =
  {
  	&quot;closeButton&quot; : true,
  	&quot;progressBar&quot; : true
  }
  		toastr.warning(&quot;{{ session('warning') }}&quot;);
  @endif
&lt;/script&gt;
 

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

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

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

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

return redirect()-&gt;route('your route name')-&gt;with('info','This is xyz information');
//So,I hope you will be successfully implement this code and disply diffrent message in your laravel applications.

4.13 (8 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source