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

👋 While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay