使用通知範本和多通知通道向使用者發送通知,支援具有巨集的 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;使用IlluminateFoundationAuthUserTFactor 作為可驗證的;使用IlluminateNotificationsNotificable;使用LvelaraFortsJetTFactorSfaraAtablem>SFaraAtablet使用LvelaratableFtFt5555; PermissionTraitsHasRoles ;使用TomatoPHPFilamentAlertsTraitsInteractsWithNotifications;類別使用者擴充了Authenticatable{使用HasApiTokens;使用HasFactory;使用HasProfilePhoto ;使用Notifying ;使用 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(字串$title,字串$message=null,?字串$url=null,?字串$image=null,?字串$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_IDURFIREBASE了嗎BASE M_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