F
Filament16mo ago
TiBiBa

Unable to display notifications in admin panel

Hi! I'm struggling with showing notifications in the admin panel. I followed the docs which described that the notifications should already be implemented within the panel. For a custom page I added the @livewire('notifications') line to the Blade template and used the Notification::make() as described in the documentation. According to the debugbar the view for a notification is indeed rendered, see the snippet below. But for some reason not visible, does someone have a solution? Thanks in advance!
38 Replies
Saade
Saade16mo ago
If you're using the admin panel already, there's no need for @livewire('notifications'), please share some code to allow us to help solve your problem
TiBiBa
TiBiBaOP16mo ago
All rights thanks for your reply! Will remove this. The use is a form submit for which we want to provide a warning notification when nothing is found following the given search criteria. Like this:
public function submit(): void
{
// Get the content

if (empty($this->content)) {
Notification::make()
->title('Nothing found for your search criteria')
->warning()
->send();
}
}
public function submit(): void
{
// Get the content

if (empty($this->content)) {
Notification::make()
->title('Nothing found for your search criteria')
->warning()
->send();
}
}
Thanks in advance!
Saade
Saade16mo ago
You're using a Filament Custom Page, or a Livewire Component? Cause there's no submit() hook
TiBiBa
TiBiBaOP16mo ago
It's a Filament custom page that implements HasForms
Saade
Saade16mo ago
how's your blade file looks like?
TiBiBa
TiBiBaOP16mo ago
<x-filament::page>
<div class="w-full flex flex-col md:flex-row gap-4">
<form class="w-96" wire:submit.prevent="submit">
{{ $this->form }}
<x-filament::button type="submit" class="mt-4" wire:loading.attr="disabled" wire:loading.class="cursor-wait opacity-70">
Search
</x-filament::button>
</form>
<x-filament::card class="w-full">
<!-- The content magic -->
</x-filament::card>
</div>
</x-filament::page>
<x-filament::page>
<div class="w-full flex flex-col md:flex-row gap-4">
<form class="w-96" wire:submit.prevent="submit">
{{ $this->form }}
<x-filament::button type="submit" class="mt-4" wire:loading.attr="disabled" wire:loading.class="cursor-wait opacity-70">
Search
</x-filament::button>
</form>
<x-filament::card class="w-full">
<!-- The content magic -->
</x-filament::card>
</div>
</x-filament::page>
Saade
Saade16mo ago
hmm everything looks correct, have you tried removing empty($this->content) just to make sure?
TiBiBa
TiBiBaOP16mo ago
Yes I did, also tried some debugging with dd() in the same if-statement, which executed as expected.
Saade
Saade16mo ago
that's odd :/ sorry i really don't know what's happening, i have a similar code that works as expected
LeandroFerreira
LeandroFerreira16mo ago
since you are using a custom form, you should do this:
public function submit() {
$data = $this->form->getState();
}
public function submit() {
$data = $this->form->getState();
}
share the whole code
TiBiBa
TiBiBaOP16mo ago
I know, I just hide my actual code in the function as it didn't seem relevant for the issue. Notice the // Get the content line in which place this is performed correctly.
LeandroFerreira
LeandroFerreira16mo ago
share the whole code..
TiBiBa
TiBiBaOP16mo ago
It doesn't matter, I just changed it to the following and it still doesn't work.
public function submit(): void
{
Notification::make()
->title('Nothing found for your search criteria')
->warning()
->send();
}
public function submit(): void
{
Notification::make()
->title('Nothing found for your search criteria')
->warning()
->send();
}
Saade
Saade16mo ago
@.tibiba do you have Broadcasting enabled on your filament config? to receive real-time notifications ...
TiBiBa
TiBiBaOP16mo ago
I thought broadcasting was only relevant for socket connections?
Saade
Saade16mo ago
yeah, it is, just though about that because of the echo.blade.php view being loaded, if that was the case, it would require you to ->toBroadcast() the notification but that's not your case then
TiBiBa
TiBiBaOP16mo ago
I understand, but I'm not using any socket connection in this project.
Saade
Saade16mo ago
please try
public function mount(): void
{
Notification::make()
->title('Nothing found for your search criteria')
->warning()
->send();
}
public function mount(): void
{
Notification::make()
->title('Nothing found for your search criteria')
->warning()
->send();
}
see if the notification appears
TiBiBa
TiBiBaOP16mo ago
This works! But how...?
Saade
Saade16mo ago
is your page reloading when you save the form? (it shouldnt) btw i suggest you to replace your <form> and <button> with:
<x-filament::form wire:submit.prevent="submit">
{{ $this->form }}

<x-filament::button type="submit">
Search
</x-filament::button>
</x-filament::form>
<x-filament::form wire:submit.prevent="submit">
{{ $this->form }}

<x-filament::button type="submit">
Search
</x-filament::button>
</x-filament::form>
TiBiBa
TiBiBaOP16mo ago
It doesn't Will do, I followed the Filament docs for this.
Saade
Saade16mo ago
yeah, the docs are for people outside filament admin, when you're using admin you can reuse ui components to keep consistency and avoid breaking ui on future updates
TiBiBa
TiBiBaOP16mo ago
I didn't know, thank you very much!
Saade
Saade16mo ago
tbh, idk i don't think its a bug because its working for me, but maybe @Dan Harrin could help you it doesn't make sense to not work there
Dan Harrin
Dan Harrin16mo ago
this really shouldnt work lol livewire cant dispatch browser events from mount()... i dont have any ideas why flash notifications dont work
Saade
Saade16mo ago
LOL even with parent::mount()? after the parent mount shouldn't the component be fully mounted on screen?
Dan Harrin
Dan Harrin16mo ago
it shouldnt work lol
TiBiBa
TiBiBaOP16mo ago
So I have something working that shouldn't but something that should doesn't? lol Will try to figure this out, thanks for all the help!
Saade
Saade16mo ago
good luck
mariateslarasu_88137
Hi @.tibiba , did you manage to find a solution for your problem? I am facing the same issue. I just need to display a message when saving an item.
TiBiBa
TiBiBaOP16mo ago
Unfortunately I did not. My best hope is to switch to v3 somewhere the following days and hope for it to work, otherwise I will dive into this again.
mariateslarasu_88137
Thank you for your reply!
Dan Harrin
Dan Harrin16mo ago
honestly i dont think its a filament problem so no clue if that will even fix it
mariateslarasu_88137
for me, notifications did not show from the beginning. not sure I did something wrong
Dan Harrin
Dan Harrin16mo ago
not being rude here, but probably? I haven't had many reports about this
mariateslarasu_88137
yes, yes, not saying you are rude. Just saying I have no clue as well
Dan Harrin
Dan Harrin16mo ago
have you tried in a new project? also, are you using the admin panel with a resource? or are you writing the notification code yourself
mariateslarasu_88137
did not try with a new project. I am using it with a resource and it also works for me if I send the notification in mounted I managed to fix this. The issue was that my session was not persistent Illuminate\Session\Middleware\StartSession:class had to be added in app/Http/Kernel.php @.tibiba , maybe it helps you as well
Want results from more Discord servers?
Add your server