Introduction
In filamentphp there are called Database notification, which is we can notify specify user. Read documentation
What's The problem?
There are a Mark all as read
action. How we can override the method of that action?
Solution
First, we need to create a livewire component, let's call it DatabaseCustomNotifications
php artisan make:livewire DatabaseCustomNotifications
That will be create file in app\Livewire\DatabaseCustomNotifications
, and looks like this
<?php
namespace App\Livewire;
use Livewire\Component;
class DatabaseCustomNotifications extends Component
{
}
Next, You need change extends to Filament\Livewire\DatabaseNotifications
.
<?php
namespace App\Livewire;
use Filament\Livewire\DatabaseNotifications;
use Livewire\Attributes\On;
use Livewire\Component;
class DatabaseCustomNotifications extends DatabaseNotifications
{
}
Next, Use the livewire component in your blade.
@livewire('database-custom-notifications')
Next, let's override markAllNotificationsAsRead
method
<?php
namespace App\Livewire;
use Filament\Livewire\DatabaseNotifications;
use Livewire\Attributes\On;
use Livewire\Component;
class DatabaseCustomNotifications extends DatabaseNotifications
{
public function markAllNotificationsAsRead(): void
{
dd("Got it");
$this->getUnreadNotificationsQuery()->update(['read_at' => now()]);
}
}
And finally, you can modify that action.
Top comments (0)