I've written some code using laravel livewire that makes a modal appear whenever a user successfully subscribes or volunteers to join my website. I've tried writing some code that delays the modal, but now it's just making my code slower instead of making some text disappear after a few seconds. Here's the code that I've written on my blade file.
<div wire:loading.delay.short class="bg-white shadow" style="border-radius: 30px">
@if (session()->has('subscription_message'))
@include('livewire.frontend.subscribe.success')
@endif
</div>
I want the subscription_message to disappear and I've also written the subscription_message on another blade file.
<div wire:loading id="modal" class="alert alert-success" role="alert">
<h6 class="alert-heading">Thank you for your Subscription!🤗</h6>
<p>{{ session('subscription_message') }}<i class="fa fa-check"></i></p>
<p class="mb-0">Kind Regards,<br>
{!! 'Ben's Team' !!}
</p>
</div>
Here's the livewire component that controlls all the code on those two blade files.
public function save()
{
$this->validateForm();
Subscription::create([
'name' => $this->name,
'email' => $this->email
]);
$name = $this->name;
$email = $this->email;
$message = "Dear $name ! Thank you for subscribing with Us, Please check your email:($email) for more information.";
$this->resetInput();
// Sent Welcome email to subscriber
Mail::to($email)->send(new WelcomeSubscriberNotification());
session()->flash('subscription_message',$message);
}
I don't know how to timeout the flash message that appears after a user has subscribed. Can any assist me on a way to solve this problem? I want to use livewire, but if that doesn't work, I'm willing to use either Jquery or Javascript.
I've got it. On the blade file which shows the success message after clicking the submit button, I just added the following js code.
Blade file
<div id="modal" class="alert alert-success" role="alert">
<h6 class="alert-heading">Thank you for your Subscription!🤗</h6>
<p>{{ session('subscription_message') }}<i class="fa fa-check"></i></p>
<p class="mb-0">Kind Regards,<br>
{!! 'Ben's Team' !!}
</p>
</div>
JS Code
var timeout = 3000; // in miliseconds (3*1000)
$('.alert').delay(timeout).fadeOut(300);</script>