tomatophp/filament-alerts
Composer 安装命令:
composer require tomatophp/filament-alerts
包简介
Send notification to users using notification templates and multi notification channels, it's support Filament Native Notification Service with macro, and a full integration to FCM service worker notifications
README 文档
README
Filament Alerts Sender
Send notification to users using notification templates and multi notification channels, it's support Filament Native Notification Service with macro, and a full integration to FCM service worker notifications
Features
- Send Notification to users using drivers
- Use Filament Native Notification
- Use Notification Templates
- Notification Logs
- Use Multiple Notification Channels
- Hide Notifications Resources
- Use Database Driver
- Use Email Driver
- Custom Driver Register
- Custom Type Register
- Custom Action Register
- Multi Users Register
- Register Notification Templates
Screenshots
Drivers
we have ready to use drivers for the Filament Alerts you can check
Installation
composer require tomatophp/filament-alerts
after install your package please run this command
php artisan filament-alerts:install
if you are not using this package as a plugin please register the plugin on /app/Providers/Filament/AdminPanelProvider.php
->plugin(\TomatoPHP\FilamentAlerts\FilamentAlertsPlugin::make() )
Usage
to set up any model to get notifications you
<?php namespace App\Models; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Fortify\TwoFactorAuthenticatable; use Laravel\Jetstream\HasProfilePhoto; use Laravel\Sanctum\HasApiTokens; use Spatie\Permission\Traits\HasRoles; use TomatoPHP\FilamentAlerts\Traits\InteractsWithNotifications; class User extends Authenticatable { use HasApiTokens; use HasFactory; use HasProfilePhoto; use Notifiable; use TwoFactorAuthenticatable; use HasRoles; use InteractsWithNotifications; ...
Queue
the notification is run on queue, so you must run the queue worker to send the notifications
php artisan queue:work
Use Filament Native Notification
you can use the filament native notification and we add some macro for you
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() ]) ->sendUse(auth()->user(), \TomatoPHP\FilamentAlerts\Services\Drivers\EmailDriver::class);
Notification Service
to create a new template you can use template CRUD and make sure that the template key is unique because you will use it on every single notification.
Send Notification
to send a notification you must use our helper SendNotification::class like
use TomatoPHP\FilamentAlerts\Facades\FilamentAlerts; FilamentAlerts::notify(User::first()) ->template($template->id) ->title([ "find-text" => "change with this" ]) ->body([ "find-text" => "change with this" ]) ->send();
where $template is selected of the template by key or id, and title, body use to select and replace string on the template with custom data
Notification Channels
you can use multiple notification channels like
- Database
- Discord
- Firebase Cloud Messages
it can be working with direct user methods like
$user->notifyEmail(string $message, ?string $subject = null, ?string $url = null); $user->notifyDB(string $message, ?string $title=null, ?string $url =null);
Hide Notifications Resources
to hide the notification resources from the sidebar you can use the plugin method hideNotificationsResources like
->plugin(\TomatoPHP\FilamentAlerts\FilamentAlertsPlugin::make() ->hideNotificationsResources() )
Use Email Settings
we have build a Email settings to change your SMTP settings direct from GUI to allow this feature just add this method to the plugin
->plugin(\TomatoPHP\FilamentAlerts\FilamentAlertsPlugin::make() ->useSettingsHub() )
Add Custom Driver
you can add a custom driver follow up Driver abstract class like this
<?php namespace TomatoPHP\FilamentAlerts\Services\Drivers; use Filament\Notifications\Notification; use TomatoPHP\FilamentAlerts\Jobs\NotifyDatabaseJob; class DatabaseDriver extends Driver { public function setup(): void { // TODO: Implement setup() method. } public function sendIt( string $title, string $model, int | string | null $modelId = null, ?string $body = null, ?string $url = null, ?string $icon = null, ?string $image = null, ?string $type = 'info', ?string $action = 'system', ?array $data = [], ?int $template_id = null, ?Notification $notification = null ): void { if ($modelId) { dispatch(new NotifyDatabaseJob([ 'model_type' => $model, 'modelId' => $modelId, 'title' => $title, 'body' => $body, 'url' => $url, 'icon' => $icon, 'type' => $type, 'action' => $action, 'data' => $data, 'template_id' => $template_id, ])); } else { foreach ($model::all() as $user) { dispatch(new NotifyDatabaseJob([ 'model_type' => $model, 'modelId' => $user->id, 'title' => $title, 'body' => $body, 'url' => $url, 'icon' => $icon, 'type' => $type, 'action' => $action, 'data' => $data, 'template_id' => $template_id, ])); } } } }
then just use the facade service method in your service provider boot()
use TomatoPHP\FilamentAlerts\Facades\FilamentAlerts; public function boot() { FilamentAlerts::register( \TomatoPHP\FilamentAlerts\Services\Concerns\NotificationDriver::make('database') ->label('Database') ->color('primary') ->icon('heroicon-o-bell') ->driver(\TomatoPHP\FilamentAlerts\Services\Drivers\DatabaseDriver::class) ); }
Register Custom Type
you can add a custom type using facade service method in your service provider boot()
use TomatoPHP\FilamentAlerts\Facades\FilamentAlerts; public function boot() { FilamentAlerts::register( \TomatoPHP\FilamentAlerts\Services\Concerns\NotificationType::make('system') ->label('System') ->color('primary') ->icon('heroicon-o-bell') ); }
Register Custom Action
you can add a custom action using facade service method in your service provider boot()
use TomatoPHP\FilamentAlerts\Facades\FilamentAlerts; public function boot() { FilamentAlerts::register( \TomatoPHP\FilamentAlerts\Services\Concerns\NotificationAction::make('system') ->label('System') ->color('primary') ->icon('heroicon-o-bell') ); }
Register Custom User Type
you can add a custom user type using facade service method in your service provider boot()
use TomatoPHP\FilamentAlerts\Facades\FilamentAlerts; public function boot() { FilamentAlerts::register( \TomatoPHP\FilamentAlerts\Services\Concerns\NotificationUser::make(User::class) ->label('User') ->color('primary') ->icon('heroicon-o-bell') ); }
User Alerts Resource Hooks
we have add a lot of hooks to make it easy to attach actions, columns, filters, etc
Table Columns
use TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Table\NotificationsTemplateTable; public function boot() { NotificationsTemplateTable::register([ \Filament\Tables\Columns\TextColumn::make('something') ]); }
Table Actions
use TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Table\NotificationsTemplateActions; public function boot() { NotificationsTemplateActions::register([ \Filament\Tables\Actions\ReplicateAction::make() ]); }
Table Filters
use TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Table\NotificationsTemplateFilters; public function boot() { NotificationsTemplateFilters::register([ \Filament\Tables\Filters\SelectFilter::make('something') ]); }
Table Bulk Actions
use TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Table\NotificationsTemplateBulkActions; public function boot() { NotificationsTemplateBulkActions::register([ \Filament\Tables\BulkActions\DeleteAction::make() ]); }
From Components
use TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Form\NotificationsTemplateForm; public function boot() { NotificationsTemplateForm::register([ \Filament\Forms\Components\TextInput::make('something') ]); }
Page Actions
use TomatoPHP\FilamentAlerts\Facades\FilamentAlerts; use TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Pages\ListNotificationsTemplates; public function boot() { FilamentAlerts::registerAction(action: [ Filament\Actions\Action::make('action') ], page: ListNotificationsTemplates::class); }
Infolist Entries
use TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Infolist\NotificationsTemplateInfoList; public function boot() { NotificationsTemplateInfoList::register([ \Filament\Infolists\Components\TextEntry::make('something') ]); }
Custom Resource Classes
you can customize all resource classes to be any class you want with the same return from the config file
/** * --------------------------------------------- * Resource Building * --------------------------------------------- * if you want to use the resource custom class */ 'resource' => [ 'table' => [ 'class' => \TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Table\NotificationsTemplateTable::class, 'filters' => \TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Table\NotificationsTemplateFilters::class, 'actions' => \TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Table\NotificationsTemplateActions::class, 'header-actions' => \TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Table\NotificationsTemplateHeaderActions::class, 'bulkActions' => \TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Table\NotificationsTemplateBulkActions::class, ], 'form' => [ 'class' => \TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Form\NotificationsTemplateForm::class, ], 'infolist' => [ 'class' => \TomatoPHP\FilamentAlerts\Filament\Resources\NotificationsTemplateResource\Infolist\NotificationsTemplateInfoList::class, ] ]
Publish Assets
you can publish config file by use this command
php artisan vendor:publish --tag="filament-alerts-config"
you can publish views file by use this command
php artisan vendor:publish --tag="filament-alerts-views"
you can publish languages file by use this command
php artisan vendor:publish --tag="filament-alerts-lang"
you can publish migrations file by use this command
php artisan vendor:publish --tag="filament-alerts-migrations"
Testing
if you like to run PEST testing just use this command
composer test
Code Style
if you like to fix the code style just use this command
composer format
PHPStan
if you like to check the code by PHPStan just use this command
composer analyse
Other Filament Packages
Checkout our Awesome TomatoPHP
tomatophp/filament-alerts 适用场景与选型建议
tomatophp/filament-alerts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.18k 次下载、GitHub Stars 达 81, 最近一次更新时间为 2024 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「php」 「email」 「notifications」 「laravel」 「filament」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tomatophp/filament-alerts 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tomatophp/filament-alerts 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tomatophp/filament-alerts 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
统计信息
- 总下载量: 12.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 81
- 点击次数: 30
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-06








