1//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.
2
3//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 <head> tag.
4
5
6
7<head>
8 <title>Laravel Toastr Notification Example - websolutionstuff.com</title>
9
10 <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-
11 alpha/css/bootstrap.css" rel="stylesheet">
12
13 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
14
15 <link rel="stylesheet" type="text/css"
16 href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
17
18 <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
19</head>
20//Then after we need to add diffrents toastr message in script tag like below.
21
22<script>
23 @if(Session::has('message'))
24 toastr.options =
25 {
26 "closeButton" : true,
27 "progressBar" : true
28 }
29 toastr.success("{{ session('message') }}");
30 @endif
31
32 @if(Session::has('error'))
33 toastr.options =
34 {
35 "closeButton" : true,
36 "progressBar" : true
37 }
38 toastr.error("{{ session('error') }}");
39 @endif
40
41 @if(Session::has('info'))
42 toastr.options =
43 {
44 "closeButton" : true,
45 "progressBar" : true
46 }
47 toastr.info("{{ session('info') }}");
48 @endif
49
50 @if(Session::has('warning'))
51 toastr.options =
52 {
53 "closeButton" : true,
54 "progressBar" : true
55 }
56 toastr.warning("{{ session('warning') }}");
57 @endif
58</script>
59
60
61//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.
62
63return redirect()->route('your route name')->with('message','Data added Successfully');
64
65return redirect()->route('your route name')->with('error','Data Deleted');
66
67return redirect()->route('your route name')->with('Warning','Are you sure you want to delete? ');
68
69return redirect()->route('your route name')->with('info','This is xyz information');
70//So,I hope you will be successfully implement this code and disply diffrent message in your laravel applications.
71
72
1<head>
2 <title>Laravel 8 Toastr Notification Example - websolutionstuff.com</title>
3
4 <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-
5 alpha/css/bootstrap.css" rel="stylesheet">
6
7 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
8
9 <link rel="stylesheet" type="text/css"
10 href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
11
12 <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
13</head>