Create and Send Digest Emails in Laravel


February 17th, 2022


The Laravel Digest package is a simple way to convert your emails into configurable digests. You can create and send digest emails using various configurable frequency types. For example, using this package, you could send a digest email to the site administrator for every 100 user registrations, a daily digest of all errors logged, or a monthly newsletter for all the posts created.

To use this package, you'll define an observer (i.e., when a new user gets created) that will add a record to the digest:

1use Hmones\LaravelDigest\Facades\Digest;
3public function created(User $user)
5 $batchId = 'userCreated';
6 $mailable = UserCreatedMailable::class;
7 $data = ['name' => $user->name];
8 // Frequency can take values such as:
9 // daily, weekly, monthly, custom, or an
10 // integer threshold (10, 20, 30, etc.)
11 $frequency = 'custom';
13 Digest::add($batchId, $mailable, $data, $frequency);

The Laravel Digest package will take care of everything else from this point on, sending emails once the frequency is met.

To get started with this package, check out the source code on GitHub, including installation instructions and usage details.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.

Laravel News Partners