Hello Dev.
nowadays, i can display you Laravel 8 Toastr Notifications example.
there are numerous varieties of notification to be had to display special messages in laravel 8 or php like, show messages the use of bootstrap modal, simple pop up notification using jquey, dispaly notification using flash message, and toastr message notification. So,in this article i will display you a way to add Toastr Notifications In Laravel 8 and how to upload custom message in toastr.
first you want to add bootstrap CSS, toastr notification jquery, toastr CSS and toastr js in you main view blade file, i have introduced under CDN in <head>
tag.
<head>
<title>Laravel 8 Toastr Notification Example - meaningarticles.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 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()->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');
i'm hoping it assist you to, thanks for visit my article if you like my article then proportion together with your friend and social platform.