使用通知模板和多通知通道向用户发送通知,支持带宏的 Filament Native 通知服务,并与 FCM Service Worker 通知完全集成
向用户发送通知
使用灯丝本机通知
使用通知模板
完整的 FCM Service Worker 集成
使用多个通知渠道
用于获取通知的 API
隐藏通知资源
使用 Slack 驱动程序
使用不和谐驱动程序
使用混响驱动器
使用 SMS Misr 驱动程序
使用电子邮件驱动程序
使用数据库驱动程序
使用 MessageBird 驱动程序
使用此软件包之前请确保您已安装
细丝空间可翻译
灯丝 Spatie 媒体库
灯丝设置中心
作曲家需要 tomatophp/filament-alerts
现在您需要发布和迁移设置表
php artisan 供应商:发布 --provider="SpatieLaravelSettingsLaravelSettingsServiceProvider" --tag="migrations"
安装软件包后请运行此命令
php artisan 灯丝警报:安装
如果您不使用此包作为插件,请在/app/Providers/Filament/AdminPanelProvider.php
上注册该插件
->插件(TomatoPHPFilamentAlertsFilamentAlertsPlugin::make() )
设置任何模型来获取通知
<?phpnamespace AppModels;使用 IlluminateContractsAuthMustVerifyEmail;使用 IlluminateDatabaseEloquentFactoriesHasFactory;使用 IlluminateFoundationAuthUser 作为可验证的;使用 IlluminateNotificationsNotifying;使用 LaravelFortifyTwoFactorAuthenticatable;使用 LaravelJetstreamHasProfilePhoto;使用 LaravelSanctumHasApiTokens;使用SpatiePermissionTraitsHasRoles;使用 TomatoPHPFilamentAlertsTraitsInteractsWithNotifications;类 User 扩展 Authenticatable{使用 HasApiTokens;使用 HasFactory;使用 HasProfilePhoto;使用 Notabile;使用 TwoFactorAuthenticatable;使用 HasRoles;使用 InteractsWithNotifications; ...
并且您必须设置 FCM 才能获取实时通知
通知在队列上运行,因此您必须运行队列工作程序来发送通知
php工匠队列:工作
您可以使用灯丝本机通知,我们为您添加一些macro
使用 FilamentNotificationsNotification;Notification::make('send') ->title('测试通知') ->body('这是一个测试通知') ->icon('heroicon-o-bell') ->颜色('成功') ->actions([FilamentNotificationsActionsAction::make('view') ->标签('视图') ->url('https://google.com') -> 标记为已读() ]) ->sendToDiscord(auth()->user()) ->sendToEmail(auth()->user()) ->广播(auth()->user()) ->sendToDatabase(auth()->user()) ->sendToSlack(auth()->user()) ->sendToFCM(auth()->user())
要创建新模板,您可以使用模板 CRUD 并确保模板密钥是唯一的,因为您将在每个通知上使用它。
要发送通知,您必须使用我们的助手 SendNotification::class ,例如
SendNotification::make($template->providers) ->模板($模板->键) ->findTitle($matchesTitle) ->replaceTitle($titleFill) ->findBody($matchesBody) ->replaceBody($titleBody) ->模型(用户::类) ->id(用户::first()->id) ->隐私('私人') -> 火();
其中$template
通过键从模板中选择,$matchesTitle 和 $matchesBody 是用于替换模板的匹配数组,$titleFill 和 $titleBody 是用于替换匹配的值数组
您可以使用多个通知渠道,例如
电子邮件
短信
流式细胞仪
混响
数据库
松弛
不和谐
它可以与直接用户方法一起使用,例如
$user->notifySMSMisr(string $message);$user->notifyEmail(string $message, ?string $subject = null, ?string $url = null);$user->notifyFCMSDK(string $message, string $type= 'web', ?string $title=null, ?string $url=null, ?string $image=null, ?string $icon=null, ?array $data=[]);$user->notifyDB(string $message, ?string $title=null, ?string $url =null);$user->notifySlack(string $title,string $message=null,?string $url=null, ?string $image=null, ?string $webhook=null);$user->notifyDiscord(string $title,string $message=null,?string $url=null, ?string $image=null, ?string $webhook=null);
要使 FCM 通知工作,您需要安装 Filament Settings Hub 并允许在插件上使用 Settings Hub
->插件(TomatoPHPFilamentAlertsFilamentAlertsPlugin::make() ->useSettingsHub() ->使用FCM() )
比您需要使用此命令安装filament-fcm
包
作曲家需要 tomatophp/filament-fcm
并添加服务提供商插件
->插件(TomatoPHPFilamentFcmFilamentFcmPlugin::make())
现在你需要更新配置
# Firebase ProjectFIREBASE_API_KEY=FIREBASE_AUTH_DOMAIN=FIREBASE_DATABASE_URL=FIREBASE_PROJECT_ID=FIREBASE_STORAGE_BUCKET=FIREBASE_MESSAGING_SENDER_ID=FIREBASE_APP_ID=FIREBASE_MEASURement_ID=# Firebase 云消息传递FIREBASE_VAPID=# Firebase 警报声音FCM_ALERT_SOUND=
比运行这个命令
php artisan 灯丝-fcm:安装
它将生成 FCM 工作程序,供您在后台发出通知。
要从侧边栏隐藏通知资源,您可以使用插件方法hideNotificationsResources
,例如
->插件(TomatoPHPFilamentAlertsFilamentAlertsPlugin::make() ->隐藏通知资源() )
要使用 slack 驱动程序,您必须在设置中心设置 slack webhook 并使用插件方法useSlack
例如
->插件(TomatoPHPFilamentAlertsFilamentAlertsPlugin::make() ->使用Slack() )
现在在您的.env
文件中添加带有 webhook URL 的SLACK_WEBHOOK
键
要使用discord驱动程序,您必须在设置中心设置discord webhook并使用插件方法useDiscord
例如
->插件(TomatoPHPFilamentAlertsFilamentAlertsPlugin::make() ->useDiscord() )
现在在您的.env
文件中添加带有 webhook URL 的DISCORD_WEBHOOK
键
我们支持一些 API 来获取通知并执行一些操作,您可以在api/notifications
路径下找到它
您可以使用插件方法apiModel
更改用户模型,例如
->插件(TomatoPHPFilamentAlertsFilamentAlertsPlugin::make() ->apiModel(用户::类) )
您可以使用此命令发布配置文件
php artisan 供应商:发布 --tag="filament-alerts-config"
您可以使用此命令发布视图文件
php artisan 供应商:发布 --tag="filament-alerts-views"
您可以使用此命令发布语言文件
php artisan 供应商:发布 --tag="filament-alerts-lang"
您可以使用此命令发布迁移文件
php artisan 供应商:发布 --tag="filament-alerts-migrations"
查看我们很棒的 TomatoPHP