Laravel Mailator provides a featherweight system for configuring email schedulers and email templates based on application events. You can install this package via composer: composer require binarcode/laravel-mailator
BeforeInvoiceExpiresConstraint constraint: class BeforeInvoiceExpiresConstraint implements SendScheduleConstraint { public function canSend(MailatorSchedule $mailatorSchedule, Collection $log): bool { // your conditions return true; }}
To create an email template: $template = Binarcode\LaravelMailator\Models\MailTemplate::create([ 'name' => 'Welcome Email.', 'from_email' => 'from@bar.com', 'from_name' => 'From Bar', 'subject' => 'Welcome to Mailator.', 'html' => '
This could be done in the build method as shown below: class WelcomeMailatorMailable extends Mailable { use Binarcode\LaravelMailator\Support\WithMailTemplate; private Model $user; public function __construct(Model $user) { $this->user = $user; } public function build() { return $this->template(MailTemplate::firstWhere('name', 'Welcome Email.')); } public function getReplacers(): array { return [ Binarcode\LaravelMailator\Replacers\ModelAttributesReplacer::makeWithModel($this->user), function($html) { // }]; }}