Reputation: 51
I am new to Programming and I am assigned to build a renting system. I'm using laravel and i'm having a hard time making a toast notification. I have no idea how can I call a toast(bootstrap)
notification whenever the costumer successfully submitted a form.
here is my controller wherein the data is submitted successfully on the database.
public function store(Request $request){
$rentform = new BorrowerRequest;
$rentform->user_id = $request->user_id;
$rentform->car_id = $request->car_id;
$rentform->borrowers_name = $request->borrowers_name;
$rentform->email = $request->email;
$rentform->return_date = $request->return_date;
$rentform->contact_number = $request->contact_number;
$rentform->request_status_id = $request->request_status_id;
$rentform->save();
$request->session()->flash('message', 'Your Request has been successfully submitted, please wait for a couple of hours for the approval');
return redirect('/selections');
}
anyone can give me a hint on how i can make a condition where a toast notification will popup in admins account whenever a formrequest is submitted by the costumer?
Upvotes: 0
Views: 7526
Reputation: 1
Answer 2 just create and alert .php file for alert and on it just check for session message like this
@if(session('message'))
<div
class="toast show bg-info fade mx-auto"
id="static-example"
role="alert"
aria-live="assertive"
aria-atomic="true"
data-mdb-autohide="false">
<div class="toast-header">
<strong class="me-auto">title</strong>
<button type="button" class="btn-close" data-mdb-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body text-white">
<p>put in ur message</p>
</div>
</div>
@endif
when u have finish with the message just go in to ur view file and include the alert.php file inside like this
@include('alert');
Upvotes: 0
Reputation: 75
you can use This package for toastr notification ,, after successfully install this package you need to link those css and js cdn in your master template..
<link rel="stylesheet" href="http://cdn.bootcss.com/toastr.js/latest/css/toastr.min.css">
<script src="http://cdn.bootcss.com/toastr.js/latest/js/toastr.min.js"></script>
{!! Toastr::message() !!}
then you can use this notification like,
$rentform->save();
Toastr::success('Post Successfully Saved :)','Success');
return redirect('/selections');
and also make sure that you need to use this line in your controller
use Brian2694\Toastr\Facades\Toastr;
for more details visit this link::
Upvotes: 1