anourvalar/eloquent-notification
最新稳定版本:1.5.14
Composer 安装命令:
composer require anourvalar/eloquent-notification
包简介
Laravel Notification - model layer
README 文档
README
Installation
Step #1: Install the package
composer require anourvalar/eloquent-notification
Step #2: Publish the resources
php artisan vendor:publish --provider=AnourValar\\EloquentNotification\\Providers\\AnourValarEloquentNotificationServiceProvider
Notification feature
Step #1: Add notification routes for User model
/** * Route notifications for the Telegram channel. * * @param \Illuminate\Notifications\Notification $notification * @return string|null */ public function routeNotificationForTelegram($notification) { return $this->telegram_chatid; // set your attribute } /** * Route notifications for the SMS channel. * * @param \Illuminate\Notifications\Notification $notification * @return string|null */ public function routeNotificationForSms($notification) { return $this->phone; // set your attribute } /** * Route notifications for the Push channel. * * @param \Illuminate\Notifications\Notification $notification * @return string|array|null */ public function routeNotificationForPush($notification) { return $this->tokens()->orderBy('id', 'DESC')->limit(10)->pluck('push_token')->toArray(); // set your attribute }
Step #2: Create a notification
namespace App\Notifications\Triggers; use Illuminate\Notifications\Messages\MailMessage; class NewPostNotification extends \AnourValar\EloquentNotification\AbstractNotification { /** * Create a new notification instance. */ public function __construct(public \App\Post $post) { parent::__construct(); } /** * Get the mail representation of the notification. */ public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->line($this->post->title) ->action('Notification Action', url('/')) ->line('Thank you for using our application!'); } }
Step #3: Collect (group) notify (optional)
App::make(Service::class)->collectNotify($user, EmailUpdatedNotification::class, []);
Confirm feature
Step #1: Add middleware to the HTTP Kernel
/** * The application's middleware aliases. * * Aliases may be used instead of class names to conveniently assign middleware to routes and groups. * * @var array<string, class-string|string> */ protected $middlewareAliases = [ // <...> 'confirm.pow' => \AnourValar\EloquentNotification\Http\Middleware\ConfirmPow::class, 'confirm.email.input' => \AnourValar\EloquentNotification\Http\Middleware\ConfirmEmailInput::class, 'confirm.email.my' => \AnourValar\EloquentNotification\Http\Middleware\ConfirmEmailMy::class, 'confirm.phone.input' => \AnourValar\EloquentNotification\Http\Middleware\ConfirmPhoneInput::class, 'confirm.phone.my' => \AnourValar\EloquentNotification\Http\Middleware\ConfirmPhoneMy::class, 'confirm.totp.input' => \AnourValar\EloquentNotification\Http\Middleware\ConfirmTotpInput::class, 'confirm.totp.my' => \AnourValar\EloquentNotification\Http\Middleware\ConfirmTotpMy::class, 'confirm.fa.my' => \AnourValar\EloquentNotification\Http\Middleware\ConfirmFaMy::class, ];
Step #2: Explore the ConfirmService
统计信息
- 总下载量: 111
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-11