Add email digests
This commit is contained in:
parent
940fa5fda4
commit
a569ac5cc6
6 changed files with 218 additions and 35 deletions
57
app/Console/Commands/SendDigest.php
Normal file
57
app/Console/Commands/SendDigest.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Mail\Digest;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendDigest extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'digest:send {--D|daily} {--W|weekly} {--M|monthly}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Send a digest of recent updates.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (!$this->option('daily') && !$this->option('weekly') && !$this->option('monthly')) {
|
||||
$this->error('No schedule specified.');
|
||||
return;
|
||||
}
|
||||
|
||||
// These are seperated because I may want to send multiple types
|
||||
// of digest in a single commend.
|
||||
if ($this->option('daily')) {
|
||||
foreach (config('app.daily_digest_recipients') as $recipient) {
|
||||
Mail::to($recipient)->send(new Digest('daily', config('app.current_trip_id')));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->option('weekly')) {
|
||||
foreach (config('app.weekly_digest_recipients') as $recipient) {
|
||||
Mail::to($recipient)->send(new Digest('weekly', config('app.current_trip_id')));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->option('monthly')) {
|
||||
foreach (config('app.monthly_digest_recipients') as $recipient) {
|
||||
Mail::to($recipient)->send(new Digest('monthly', config('app.current_trip_id')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue