64robots/batch-notifications
Composer 安装命令:
composer require 64robots/batch-notifications
包简介
A Laravel package that groups repetitive notifications in batches
关键字:
README 文档
README
Description
Batch Notifications is a Laravel package that groups repetitive notifications in batches. This package is intended for cases where notifications are dispatched repeatedly for a same Notifiable model. So, instead of sending lots of notifications (ex.: email messages) repeatedly to the Notifiable model, the notifications are grouped in batches that will be sent in periods of time.
Installation
1 - Require the package
composer require 64robots/batch-notifications
2 - Publish
php artisan vendor:publish --provider="R64\BatchNotifications\BatchNotificationsServiceProvider"
3 - Run the migration that was just published
php artisan migrate
Usage
1 - Create you notification as you normally do, but add the "$eventables" parameter to the constructor:
class DocumentAssignedEmail extends Notification implements ShouldQueue
{
use Queueable;
/** @var Collection $eventables */
private $eventables;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Collection $eventables)
{
$this->eventables = $eventables;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
if ($this->eventables->count() == 1) {
return (new MailMessage)->view('mail.documents-assigned', [
'user' => $notifiable,
'document' => $this->eventables->first(),
])->subject("New Document Assigned");
}
return (new MailMessage)->view('mail.documents-assigned', [
'user' => $notifiable,
'documents' => $this->eventables,
])->subject("New Documents Assigned");
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
2 - Create the notification event for the intended notification:
BatchNotificationEvent::queue(
Auth::user(), /* The notifiable model instance. This can be any Notifiable Eloquent model */
$document, /* The eventable instance you want to attach to the notification. All batch's eventables will be present on your notification constructor. This can be any Eloquent model. */
DocumentAssignedEmail::class, /* The fully qualified name of your notification class */
now()->addMinutes(2) /* The minimum interval that the notifiable model will be notified. In this example, the notifications will be sent every two minutes */
);
3 - Add the command to your Console/Kernel.php file:
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('batch-notifications:dispatch')->everyMinute();
}
//...
}
4 - "mail.documents-assigned" view example:
@extends('layouts.email')
@section('content')
<p style="color: #444444">
Hello {{ $user->first_name }},
</p>
@if (isset($document))
<p style="color: #444444">
A new document has been assigned to you: <a href="{{ url('/documents/' . $document->id) }}">Document #{{ $document->id }}</a>.
</p>
@else
<p style="color: #444444">
New documents have been assigned to you:<br/><br/>
@foreach ($documents as $document)
<a href="{{ url('/documents/' . $document->id) }}">Document #{{ $document->id }}</a><br/>
@endforeach
</p>
@endif
@endsection
64robots/batch-notifications 适用场景与选型建议
64robots/batch-notifications 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.37k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2018 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notifications」 「laravel」 「batch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 64robots/batch-notifications 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 64robots/batch-notifications 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 64robots/batch-notifications 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
Fork of Maatwebsite for reasons of incompatibility with php >= 7.4 --- of Supercharged Excel exports in Laravel
Library with classes to help you do batch.
Supercharged Excel exports and imports in Laravel
Captures outgoing SMS notifications
Deferred batch construction for Laravel job chains
统计信息
- 总下载量: 2.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-05