DEV Community

Rupadana
Rupadana

Posted on

7

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more