session message is not printing in layout blade file.
livewire component code:
session()->flash('message', [
'text'=>'create successfully',
'type'=>'success',
]);
layouts/admin.blade.php
@if (session()->has('message.text'))
<div class="alert
{{ session('message.type') === 'success' ? 'alert-success' : 'alert-danger' }} alert-dismissible fade show"
data-cy="alert-message"
>
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ session('message.text') }}</strong>
</div>
@endif
| GET|HEAD | owner/category | category | App\Http\Livewire\Owner\Category\CategoryView | web |
| | | | | | auth:owner |
| | GET|HEAD | owner/category-create/{id} | category.create | App\Http\Livewire\Owner\Category\CategoryCreate | web |
| | | | | | auth:owner |
| | GET|HEAD | owner/category-update/{id} | category.update | App\Http\Livewire\Owner\Category\CategoryUpdate | web |
| | | | | | auth:owner
My Answer:
It looks like you are trying to display a session message in your custom blade layout file in a Laravel Livewire component.
First, make sure that you are flashing the session message correctly in your Livewire component. The code you provided seems correct for flashing a success message.
Next, in your custom blade layout file, you are checking if the session has a key 'message.text' but you are accessing it incorrectly. Instead of `session('message.text')`, you should use `session('message')['text']` to access the 'text' value of the message.
Here is the corrected code for your custom blade layout file:
php
@if (session()->has('message'))
@endif
Make sure to also check if the session message is being flashed correctly in your Livewire component and that the layout file is being included in your Livewire component view file.
If you are still facing issues, try debugging by dumping the session data in your Livewire component and layout file to see if the session message is being set and accessed correctly.
Rate this post
3 of 5 based on 6971 votesComments