PHP code example of riazxrazor / laravel-sweet-alert
1. Go to this page and download the library: Download riazxrazor/laravel-sweet-alert library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// in the controller method
\LaravelSweetAlert::setMessageSuccess("flash message")
\LaravelSweetAlert::setMessageError("error flash message")
\LaravelSweetAlert::setMessageSuccessConfirm("flash message")
\LaravelSweetAlert::setMessageErrorConfirm("error flash message")
// for more customization
LaravelSweetAlert::setMessage([
'title' => 'Successful',
'text' => $text,
'timer' => 2000,
'type' => 'success',
'showConfirmButton' =>false
]);
\LaravelSweetAlert::setMessage([
'title' => 'Auto close alert!',
'text' => 'I will close in 5 seconds.',
'timer' => 5000,
'onOpen' => '() => { swal.showLoading() }',
],
// second argument array of js function each element will be a then to swal
['(result) => {
if (
// Read more about handling dismissals
result.dismiss === swal.DismissReason.timer
) {
console.log("I was closed by the timer")
}
}'],
// third argument is a catch function to the promise of swal
'(e)=>console.log(e)');