I need help with sweetalert2, I have a validation in the controller which returns me with a with('statusX')
and I need a sweetalert depending on the return
try calling the sweetalert withtarget: document.getElementById('status1')
return in controller
` return redirect()->back()->with('status1'); return redirect()->back()->with('status2'); `
HTML
@if(session('status1'))
<div id="status1"></div>
@endif
@if(session('status2'))
<div id="status2"></div>
@endif
sweetalert2
<script>
Swal.fire({
type: 'success',
title: 'Tu evento ha sido añadido!',
showConfirmButton: true,
target: document.getElementById('status1')
})
</script>
I need that when the validation is correct, the corresponding sweetalert2 alert appears.
Currently when I press the save button of my form, whatever the validation, the alert opens, also when reloading the page
I use sweetalert like this, in your controller you can return like this
Where the variable
$message
would be like thisIn your file
blade.php
you can use syntax like this to select the type of alert you wantThis will check if the variable exists
message
and it already has the 2 necessary parameters,type
andmessage
, you just have to customize the alert you want to use from the library, in this case I am using thetoast