To pass the session message from the Livewire component to the blade page and display it in the toast, you can use Livewire's built-in event system and JavaScript.
First, you need to modify your blade component to include an event listener for the showMessage event emitted by the Livewire component. When the event is triggered, it will update the toast message and show it on the page.
Here's the modified blade component code:
@if(session()->has('message'))
<div class="position-fixed bottom-0 end-0 p-3" style="position: absolute; top: 20px; right: 10px;z-index:1000;width:350px;">
<div role="alert" aria-live="assertive" aria-atomic="true" class="toast" data-delay="12000" style="background-color:#3e5872;color:white">
<div class="toast-header">
<img src="{{ asset('/media/images/fireops_logo_red.png') }}" class="rounded mr-2" alt="..." width="20px;">
<strong class="mr-auto">ALERT</strong>
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="toast-body">
{!! session('message') !!}
</div>
</div>
</div>
@endif
@push('scripts')
<script>
document.addEventListener('livewire:load', function () {
Livewire.on('showMessage', function (data) {
// Update the toast message
document.querySelector('.toast-body').innerHTML = data.message;
// Show the toast
$('.toast').toast('show');
});
});
</script>
@endpush
In the JavaScript code, we listen for the livewire:load event to ensure that the Livewire component is fully loaded before attaching the event listener. When the showMessage event is triggered, we update the toast message with the new message and then show the toast using the Bootstrap toast functionality.
Make sure to include the above code in your blade component file.
Note: You need to have the Bootstrap JavaScript library included in your project for the toast functionality to work.
I hope this helps! Let me know if you have any further questions.