Adding Toastr Notifications to your Laravel App

Pinterest LinkedIn Tumblr

Adding Toastr Notifications to your Laravel App

However you decide to include it in your project you will then need to add the location to the 2 files in the <head> tag of your master layout file like so:

<script src="//"></script>
<link rel="stylesheet" type="text/css" href="//">

Then whenever you need to redirect to a page and pass a notification you can pass the redirect a notification array like so:

$notification = array(
	'message' => 'I am a successful message!', 
	'alert-type' => 'success'

return Redirect::to('/')->with($notification);

Then at the bottom of your master layout file (master.blade.php or app.blade.php) you will need to include the following javascript to show the notification type and the message you want to show:

    var type = "{{ Session::get('alert-type', 'info') }}";
        case 'info':
  "{{ Session::get('message') }}");
        case 'warning':
            toastr.warning("{{ Session::get('message') }}");

        case 'success':
            toastr.success("{{ Session::get('message') }}");

        case 'error':
            toastr.error("{{ Session::get('message') }}");

And it’s as easy as that. Make sure in the $notification array from step 2 that you specify whether you want the message to be an alert-type of infowarningsuccess, or error and the correct color notification will be shown.

Read More:

Write A Comment