Notification feed for Filament with actions support
You can install the package via composer:
composer require webbingbrasil/filament-notification
Use render-hooks to register notification feed component after global search
Filament::registerRenderHook(
'global-search.end',
fn (): string => Blade::render('@livewire(\'filament-notification.feed\')'),
);
All database notification are displayed in feed, so you will need to configure via()
to use database provider and message in toArray()
or toDatabase()
methods.
<?php
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use Webbingbrasil\FilamentNotification\Notifications\NotificationLevel;
class UserNotification extends Notification
{
public function via($notifiable)
{
return [
'database'
];
}
public function toArray($notifiable)
{
return [
'level' => NotificationLevel::INFO,
'title' => 'Info notification',
'message' => 'Lorem ipsum'
];
}
}
You can add actions to any notification displayed in feed using notificationFeedActions()
method:
<?php
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use Webbingbrasil\FilamentNotification\Actions\ButtonAction;
class UserNotification extends Notification
{
static public function notificationFeedActions()
{
return [
ButtonAction::make('markRead')->icon('heroicon-o-check')
->label('Mark as read')
->hidden(fn($record) => $record->read()) // Use $record to access/update notification, this is DatabaseNotification model
->action(function ($record, $livewire) {
$record->markAsRead();
$livewire->refresh(); // $livewire can be used to refresh ou reset notification feed
})
->outlined()
->color('secondary'),
ButtonAction::make('profile')
->label('Complete Profile')
->hidden(fn($record) => $record->read())
->icon('heroicon-o-user')
->action(function ($record, $livewire, $data) {
$record->markAsRead();
$livewire->refresh();
Auth::user()->update($data);
})
->form([
DatePicker::make('birthday')
->label('Birthday')
->required(),
])
->modalHeading('Complete Profile')
->modalSubheading('Complete you profile information')
->modalButton('Save')
->outlined()
->color('secondary'),
];
}
}
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.