webbingbrasil/filament-notification

A notification center package for filament.

v0.1.1 2022-06-11 17:27 UTC

This package is auto-updated.

Last update: 2024-11-10 02:04:39 UTC


README

Notification feed for Filament with actions support

Installation

You can install the package via composer:

composer require webbingbrasil/filament-notification

Add notification feed icon

Use render-hooks to register notification feed component after global search

Filament::registerRenderHook(
    'global-search.end',
    fn (): string => Blade::render('@livewire(\'filament-notification.feed\')'),
);

Configure notification

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'
        ];
    }
}

Notification actions

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

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.