hmones/laravel-digest
Composer 安装命令:
composer require hmones/laravel-digest
包简介
A simple package to create and send digest emails every certain period or when the amount reaches a certain threshold.
关键字:
README 文档
README
A simple package to create and send digest emails every certain period or when the amount reaches a certain threshold. Usage Examples:
- Sending a digest email to website administrator every new 100 registrations on the website.
- Sending a daily email with logged error messages on the website.
- Sending users a monthly newsletter that contains all posts issued in the month.
Installation
Via Composer
composer require hmones/laravel-digest
Configuration
To publish the package configuration
php artisan vendor:publish --tag=laravel-digest-config
The configuration file contains the following parameters:
method: the method that you would like to use to send emails, it takes two values,queueorsend- Env variable:
DIGEST_METHOD - Default value:
queue
- Env variable:
frequency.enabledwhether you would like to enable sending emails every certain period, if not enabled emails will not be scheduled- Env variable:
DIGEST_FREQUENCY_ENABLED - Default value:
true
- Env variable:
frequency.daily.timeif frequency is enabled this parameter is used as the time to send the daily digest emails- Env variable:
DIGEST_DAILY_TIME - Default value:
00:00
- Env variable:
frequency.weekly.timeif frequency is enabled this parameter is used as the time to send the weekly digest emails- Env variable:
DIGEST_WEEKLY_TIME - Default value:
00:00
- Env variable:
frequency.monthly.timeif frequency is enabled this parameter is used as the time to send the monthly digest emails- Env variable:
DIGEST_MONTHLY_TIME - Default value:
00:00
- Env variable:
frequency.weekly.dayif frequency is enabled this parameter is used as the day to send the weekly digest emails (1 is Sunday and 7 is Saturday)- Env variable:
DIGEST_WEEKLY_DAY - Default value:
1
- Env variable:
frequency.monthly.dayif frequency is enabled this parameter is used as the day to send the monthly digest emails- Env variable:
DIGEST_MONTHLY_DAY - Default value:
1
- Env variable:
frequency.customyou can set as much custom frequency definitions as you want and the parameter takes a valid cron expressionamount.enabledwhether you would like to enable sending emails every certain amount per batch- Env variable:
DIGEST_AMOUNT_ENABLED - Default value:
true
- Env variable:
amount.thresholdthe number of emails after which an digest email should be sent.- Env variable:
DIGEST_AMOUNT_THRESHOLD - Default value:
10
- Env variable:
Usage
To create an email digest, make sure you have the following first:
- A mailable, configured with the sending addresses and email views and subject.
- The mailable should accept an array variable in its constructor, this array variable will contain all the records of data passed to individual emails concatenated and sent automatically by the package to the mailable to compile the views for sending the digest.
Example: Sending a digest email every time 10 new users register on the website with a summary of their names.
- Adjust the configuration variable in
config\laravel-digest.phpby settingamount.enabled => trueandfrequency.enabled => false - Create the following mailable
<?php namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; class UserCreatedMailable extends Mailable { use Queueable, SerializesModels; public $data; public function __construct(array $data) { $this->data = $data; } public function build(): Mailable { return $this->view('userCreated')->subject('10 new users are registered')->to('email@test.com'); } }
- Create a view to render the names of the users
resources\userCreated.blade.php
<html> <head><title>Sample Email</title></head> <body> <h1>The following users have just registered:</h1> <ol> @foreach($data as $record) <li>{{$record['name']}}</li> @endforeach </ol> </body> </html>
- Create an observer for user creation and add an record to the digest every time a user is created:
<?php namespace App\Observers; use App\Mail\UserCreatedMailable; use App\Models\User; use Hmones\LaravelDigest\Facades\Digest; class UserObserver { public function created(User $user) { $batchId = 'userCreated'; $mailable = UserCreatedMailable::class; //Data can also be set to null if you don't want to attach any data to the email $data = ['name' => $user->name]; //Frequency can take values such as daily, weekly, monthly, custom or an integer threshold 10, 20 ...etc $frequency = 10; Digest::add($batchId, $mailable, $data, $frequency); } }
- The package will take care of everything else and send emails once the number of registered users reach 10.
Change log
Please see the changelog for more information on what has changed recently.
Testing
composer test
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email author email instead of using the issue tracker.
Credits
License
Please see the license file for more information.
hmones/laravel-digest 适用场景与选型建议
hmones/laravel-digest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 76.93k 次下载、GitHub Stars 达 158, 最近一次更新时间为 2022 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「LaravelDigest」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hmones/laravel-digest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hmones/laravel-digest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hmones/laravel-digest 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
Turn any PDF into a Pingen-ready A4 letter (generated address cover page + A4 normalisation + safe margins) and send it through the Pingen print & mail API. Laravel-first.
统计信息
- 总下载量: 76.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 158
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-04