I have this message notification when I add, edit, and delete but when the error on the field for example, I leave the textbox empty then the error will pop up, but the error is not a toast it is a div class="alert alert-danger>
. Can you help me on how to convert this into toastr?
Here is my error on messages.blade.php
@if(count($errors) > 0)
@foreach($errors->all() as $error)
<div class="alert alert-danger">
{{$error}}
</div>
@endforeach
@endif
I have this toastr
working on my scripts and success
, info
are working prettty well, but the error as I said is not working.
<script
src="//cdnjs.cloudflare/ajax/libs/jquery/2.0.3/jquery.min.js">
</script>
<script type="text/javascript"
src="//cdnjs.cloudflare/ajax/libs/toastr.js/latest/js/toastr.min.js">
</script>
<script>
@if(Session::has('message'))
var type="{{Session::get('alert-type','info')}}"
switch(type){
case 'info':
toastr.info("{{ Session::get('message') }}");
break;
case 'success':
toastr.success("{{ Session::get('message') }}");
break;
case 'warning':
toastr.warning("{{ Session::get('message') }}");
break;
case 'error':
toastr.error("{{ Session::get('message') }}");
break;
}
@endif
</script>
My controller:
Here is where I return my view when the page is successfully created:
$notification = array(
'message' => 'Employee Information Created!',
'alert-type' => 'success'
);
return redirect('/admin/employeemaintenance/show')
->with( $notification, 'Employee Information Created');
How to solve this?
I have this message notification when I add, edit, and delete but when the error on the field for example, I leave the textbox empty then the error will pop up, but the error is not a toast it is a div class="alert alert-danger>
. Can you help me on how to convert this into toastr?
Here is my error on messages.blade.php
@if(count($errors) > 0)
@foreach($errors->all() as $error)
<div class="alert alert-danger">
{{$error}}
</div>
@endforeach
@endif
I have this toastr
working on my scripts and success
, info
are working prettty well, but the error as I said is not working.
<script
src="//cdnjs.cloudflare./ajax/libs/jquery/2.0.3/jquery.min.js">
</script>
<script type="text/javascript"
src="//cdnjs.cloudflare./ajax/libs/toastr.js/latest/js/toastr.min.js">
</script>
<script>
@if(Session::has('message'))
var type="{{Session::get('alert-type','info')}}"
switch(type){
case 'info':
toastr.info("{{ Session::get('message') }}");
break;
case 'success':
toastr.success("{{ Session::get('message') }}");
break;
case 'warning':
toastr.warning("{{ Session::get('message') }}");
break;
case 'error':
toastr.error("{{ Session::get('message') }}");
break;
}
@endif
</script>
My controller:
Here is where I return my view when the page is successfully created:
$notification = array(
'message' => 'Employee Information Created!',
'alert-type' => 'success'
);
return redirect('/admin/employeemaintenance/show')
->with( $notification, 'Employee Information Created');
How to solve this?
Share Improve this question edited Jul 13, 2020 at 9:18 mkrieger1 23.4k7 gold badges64 silver badges81 bronze badges asked Dec 7, 2018 at 3:21 user10701881user10701881 2-
In order for
error
to work you'll need to send'alert-type' => 'error'
– Adam Rodriguez Commented Dec 7, 2018 at 3:44 - can you give the code? there are many alert on my code im confused sorry – user10701881 Commented Dec 7, 2018 at 3:54
1 Answer
Reset to default 6If you want to toast errors, I think the simplest way might be to swap the alert-danger
for a toastr:
<script>
@if(count($errors) > 0)
@foreach($errors->all() as $error)
toastr.error("{{ $error }}");
@endforeach
@endif
</script>
You will probably want to setup the toastr to prevent duplicates:
toastr.options = {
"preventDuplicates": true
}