Skip to content

Instantly share code, notes, and snippets.

@catwhocode
Created March 23, 2022 22:25
Show Gist options
  • Save catwhocode/eba13ac129f18799a80a9f5914135fe4 to your computer and use it in GitHub Desktop.
Save catwhocode/eba13ac129f18799a80a9f5914135fe4 to your computer and use it in GitHub Desktop.
Laravel LiveWire: Hide session flash for a few seconds
<?php
public function save()
{
session()->flash('message','Errorrrrr');
$this->emit('alert_remove');
return;
}
<?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