To add Tostr inyour laravel Project
1. Go to https://github.com/CodeSeven/toastr where you can see all details about toastr notifications.
2. Save each JS and CSS
3. Add the toastr in your project template. in my case it is the app.blade.php
At your header
<link rel="stylesheet" href="{{ asset('css/toastr.min.css')}}">
Add Jquery library below your css
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Before the end tag of your body
<script src="{{ asset('js/toastr.min.js')}}"></script>
4. You can now add toast notifications.
add an extra script below the import of tostr.min.js
<script src="{{ asset('js/toastr.min.js')}}"></script>
<script>
toastr.info('Are you the 6 fingered man?')
</script>
For more example how to use it, refer to this link and demo
https://codeseven.github.io/toastr/demo.htmlIn your laravel you can produce a session and trigger the toastr once there is a certain session you want.
Ex:
In my categories controller I made a session once a category was created
public function store(Request $request)
{
//
$this->validate($request,[
'name'=>'required'
]);
// dd($request);
$category = new Category;
$category->name = $request->name;
$category->save();
Session::flash('success', 'You successfully created a category');
return redirect()->route('categories');
}
Then in my app.blade.php I made a condition that will check if there is a success session then put the value in a toastr
<script>
@if(Session::has('success'))
toastr.success("{{ Session::get('success')}}");
@endif
</script>
Comments:
Post a Comment
Enter your comment...