tomatophp / filament-fcm
Firebase Cloud Messaging集成到原生FilamentPHP通知包
v1.0.10
2024-06-24 13:55 UTC
Requires
- php: ^8.1|^8.2
- filament/filament: ^3.0.0
- filament/notifications: ^3.0.0
- mobiledetect/mobiledetectlib: ^4.8
- tomatophp/console-helpers: ^1.1
- tomatophp/fcm-notifications: ^1.0
README
Filament Firebase集成
Firebase Cloud Messaging集成到原生FilamentPHP通知包
安装
composer require tomatophp/filament-fcm
安装您的包后,您需要更新.env
文件中的这些密钥
# Firebase Project FIREBASE_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 Admin SDK FIREBASE_CREDENTIALS= # Firebase Cloud Messaging FIREBASE_VAPID= # Firebase Alert Sound FCM_ALERT_SOUND=
更新后请清除配置
php artisan config:clear
然后请运行以下命令
php artisan filament-fcm:install
如果您不是将此包用作插件,请在/app/Providers/Filament/AdminPanelProvider.php
中注册插件
->plugin(\TomatoPHP\FilamentFcm\FilamentFcmPlugin::make() )
使用方法
您可以使用Filament原生通知,我们还为您添加了一些宏
use Filament\Notifications\Notification; Notification::make('send') ->title('Test Notifications') ->body('This is a test notification') ->icon('heroicon-o-bell') ->color('success') ->actions([ \Filament\Notifications\Actions\Action::make('view') ->label('View') ->url('https://google.com') ->markAsRead() ]) ->sendToFCM( user: auth()->user(), data: [ 'key' => 'value' ], sendToDatabase: false, type: 'fcm-web' // or fcm-api )
或者您可以直接从用户模型发送
$user->notifyFCMSDK( message: $this->message, type: $this->provider, title: $this->title, url: $this->url, image: $this->image, icon: $this->icon, data: [ 'url' => $this->url, 'id' => $this->model_id, 'actions' => [], 'body' => $this->message, 'color' => null, 'duration' => null, 'icon' => $this->icon, 'iconColor' => null, 'status' => null, 'title' => $this->title, 'view' => null, 'viewData' => null, 'data'=> $this->data ], sendToDatabase: false );
发布资产
您可以通过使用此命令来发布配置文件
php artisan vendor:publish --tag="filament-fcm-config"
您可以通过使用此命令来发布视图文件
php artisan vendor:publish --tag="filament-fcm-views"
您可以通过使用此命令来发布迁移文件
php artisan vendor:publish --tag="filament-fcm-migrations"
其他Filament包
查看我们的Awesome TomatoPHP