webbingbrasil / filament-notification
用于丝材的通知中心包。
v0.1.1
2022-06-11 17:27 UTC
Requires
- php: ^8.0
- filament/filament: ^2.0
- spatie/laravel-package-tools: ^1.9.2
README
支持操作的通知源
安装
您可以通过 composer 安装此包
composer require webbingbrasil/filament-notification
添加通知源图标
使用 render-hooks 在全局搜索后注册通知源组件
Filament::registerRenderHook( 'global-search.end', fn (): string => Blade::render('@livewire(\'filament-notification.feed\')'), );
配置通知
所有数据库通知都显示在源中,因此您需要配置 via()
以使用数据库提供者,并在 toArray()
或 toDatabase()
方法中指定消息。
<?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' ]; } }
通知操作
您可以使用 notificationFeedActions()
方法向源中显示的任何通知添加操作。
<?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 了解最近的变化。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。