Created
March 23, 2022 22:25
-
-
Save catwhocode/eba13ac129f18799a80a9f5914135fe4 to your computer and use it in GitHub Desktop.
Laravel LiveWire: Hide session flash for a few seconds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function save() | |
{ | |
session()->flash('message','Errorrrrr'); | |
$this->emit('alert_remove'); | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// source: | |
// https://forum.laravel-livewire.com/t/how-to-hidden-session-flash-after-few/3527/5 | |
@if(session()->has('message')) | |
<div class="alert alert-success"> | |
<button type="button" class="close" data-dismiss="alert">×</button> | |
{{ session('message') }} | |
</div> | |
@endif | |
?> | |
<script> | |
$(document).ready(function(){ | |
window.livewire.on('alert_remove',()=>{ | |
setTimeout(function(){ $(".alert-success").fadeOut('fast'); | |
}, 3000); // 3 secs | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment