DEV Community

Rupadana
Rupadana

Posted on

Filamentphp 3 : Custom Database Notification Actions

Introduction

In filamentphp there are called Database notification, which is we can notify specify user. Read documentation

What's The problem?

Image description

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


Enter fullscreen mode Exit fullscreen mode

That will be create file in app\Livewire\DatabaseCustomNotifications, and looks like this



<?php

namespace App\Livewire;

use Livewire\Component;

class DatabaseCustomNotifications extends Component
{
}



Enter fullscreen mode Exit fullscreen mode

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
{
}


Enter fullscreen mode Exit fullscreen mode

Next, Use the livewire component in your blade.



@livewire('database-custom-notifications')


Enter fullscreen mode Exit fullscreen mode

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()]);
    }
}


Enter fullscreen mode Exit fullscreen mode

And finally, you can modify that action.

Image description

Top comments (0)