EmilioBravo / filament-notification

Notification feed plugin for filament

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filament Notification (WIP)

Notification feed for Filament with actions support

Installation

You can install the package via composer:

composer require webbingbrasil/filament-notification

Add notification feed icon

First you will need to publish filament views

php artisan vendor:publish --tag=filament-views

add @livewire('filament-notification.feed') to resources/views/vendor/filament/components/layouts/app.blade.php before top bar user menu:

...
    <div class="flex-1 flex gap-4 items-center justify-between">
        <x-filament::layouts.app.topbar.breadcrumbs :breadcrumbs="$breadcrumbs" />

        @livewire('filament.core.global-search')
        
        <!–– add notification feed icon before top bar user menu ––>
        @livewire('filament-notification.feed') 
        
        <x-filament::layouts.app.topbar.user-menu />
    </div>
...

After that, delete unused views from resources/views/vendor/filament

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.

About

Notification feed plugin for filament

License:MIT License


Languages

Language:PHP 65.1%Language:Blade 34.9%