wpzag/laravel-notifications

这是我的包 laravel-notifications

v1.0.4 2022-08-05 22:23 UTC

This package is auto-updated.

Last update: 2024-09-06 02:33:11 UTC


README

安装

您可以通过 composer 安装此包

composer require wpzag/laravel-notifications

创建通知表

php artisan notifications:table
php artisan migrate

用法

  1. 首先,我们需要在用户模型中使用 Notifiable 特性
    use Wpzag\LaravelNotifications\Traits\Notifiable;
    class User extends Authenticatable
    {
        use Notifiable;
     }
  1. 然后,我们需要创建一个继承自 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'];
		}
	}
  1. 在 lang/en 中创建 notifications.php 并在翻译文件中添加条目
return [
  'user_updated' => ':user has updated his profile',
  'titles' => [ 'user_updated' => 'User Updated' ],
]
  1. 通知用户
   User::first()->notify(
         TestNotification::create(
                 key: 'user_updated',
                 relations: ['user' => User::first()],
                 data: ['random' => 'data']
    ));
  1. 然后我们可以用以下方式获取通知:
  use Wpzag\LaravelNotifications\LaravelNotifications;
  LaravelNotifications::getPaginatedNotifications();

测试

composer test

变更日志

有关最近更改的更多信息,请参阅 变更日志

贡献

有关详细信息,请参阅 贡献指南

安全漏洞

请查看 我们的安全策略,了解如何报告安全漏洞。

致谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件