wpzag / laravel-notifications
这是我的包 laravel-notifications
v1.0.4
2022-08-05 22:23 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.9.2
- staudenmeir/eloquent-json-relations: ^1.1
Requires (Dev)
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpunit/phpunit: ^9.5
README
安装
您可以通过 composer 安装此包
composer require wpzag/laravel-notifications
创建通知表
php artisan notifications:table php artisan migrate
用法
- 首先,我们需要在用户模型中使用 Notifiable 特性
use Wpzag\LaravelNotifications\Traits\Notifiable; class User extends Authenticatable { use Notifiable; }
- 然后,我们需要创建一个继承自 BaseNotification 类的通知类
<?php namespace App\Notifications; use Wpzag\LaravelNotifications\BaseNotification; class TestNotification extends BaseNotification { public function getTranslationParams() : array { return [ 'user'=>'user.name', ]; } public function getNotificationLink() : string { return 'users/'.$this->relations['user']['id']; } }
- 在 lang/en 中创建 notifications.php 并在翻译文件中添加条目
return [ 'user_updated' => ':user has updated his profile', 'titles' => [ 'user_updated' => 'User Updated' ], ]
- 通知用户
User::first()->notify( TestNotification::create( key: 'user_updated', relations: ['user' => User::first()], data: ['random' => 'data'] ));
- 然后我们可以用以下方式获取通知:
use Wpzag\LaravelNotifications\LaravelNotifications; LaravelNotifications::getPaginatedNotifications();
测试
composer test
变更日志
有关最近更改的更多信息,请参阅 变更日志。
贡献
有关详细信息,请参阅 贡献指南。
安全漏洞
请查看 我们的安全策略,了解如何报告安全漏洞。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。