PHPackages                             hmones/laravel-digest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. hmones/laravel-digest

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

hmones/laravel-digest
=====================

A simple package to create and send digest emails every certain period or when the amount reaches a certain threshold.

v2.4.0(7mo ago)15869.3k—7.6%11[1 PRs](https://github.com/hmones/laravel-digest/pulls)MITPHPPHP ^7.4|^8.0|&lt;=8.4CI passing

Since Feb 7Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/hmones/laravel-digest)[ Packagist](https://packagist.org/packages/hmones/laravel-digest)[ Docs](https://github.com/hmones/laravel-digest)[ RSS](/packages/hmones-laravel-digest/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (9)Used By (0)

Laravel Digest
==============

[](#laravel-digest)

[![Build Status](https://github.com/hmones/laravel-digest/actions/workflows/build.yml/badge.svg)](https://github.com/hmones/laravel-digest/actions)[![Style CI](https://camo.githubusercontent.com/8443eef705fa441dff4a55a275e24cd7d1d02242798b86e9563c0b0b73e4c9a4/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3435303435373032312f736869656c64)](https://github.styleci.io/repos/450457021)[![Total Downloads](https://camo.githubusercontent.com/a18ba8aec165b27021646209e257b05685194c52897d0efe927ba40c7d76c91b/687474703a2f2f706f7365722e707567782e6f72672f686d6f6e65732f6c61726176656c2d6469676573742f646f776e6c6f616473)](https://packagist.org/packages/hmones/laravel-digest)[![Latest Stable Version](https://camo.githubusercontent.com/9f2c99d636c62f3817bd399a8aaac83be2225b301b9bceb280a772a3e56fa765/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f686d6f6e65732f6c61726176656c2d646967657374)](https://packagist.org/packages/hmones/laravel-digest)[![License](https://camo.githubusercontent.com/2d29160de3343394e51326a782e6e25bfce213c6881166d1e4f7b01949d1bf48/687474703a2f2f706f7365722e707567782e6f72672f686d6f6e65732f6c61726176656c2d6469676573742f6c6963656e7365)](https://packagist.org/packages/hmones/laravel-digest)

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
------------

[](#installation)

Via Composer

```
composer require hmones/laravel-digest
```

Configuration
-------------

[](#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, `queue` or `send`
    - Env variable: `DIGEST_METHOD`
    - Default value: `queue`
- `frequency.enabled` whether 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`
- `frequency.daily.time` if 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`
- `frequency.weekly.time` if 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`
- `frequency.monthly.time` if 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`
- `frequency.weekly.day` if 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`
- `frequency.monthly.day` if frequency is enabled this parameter is used as the day to send the monthly digest emails
    - Env variable: `DIGEST_MONTHLY_DAY`
    - Default value: `1`
- `frequency.custom` you can set as much custom frequency definitions as you want and the parameter takes a valid cron expression
- `amount.enabled` whether you would like to enable sending emails every certain amount per batch
    - Env variable: `DIGEST_AMOUNT_ENABLED`
    - Default value: `true`
- `amount.threshold` the number of emails after which an digest email should be sent.
    - Env variable: `DIGEST_AMOUNT_THRESHOLD`
    - Default value: `10`

Usage
-----

[](#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.

1. Adjust the configuration variable in `config\laravel-digest.php` by setting `amount.enabled => true` and `frequency.enabled => false`
2. Create the following mailable

```
