mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-21 05:24:01 +00:00
75 lines
1.7 KiB
PHP
75 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Classes\Notifications\PermitsReminderEmail;
|
|
use App\Models\PermitsReminder;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Command;
|
|
|
|
class SendPermitsReminderEmails extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'permitsReminder:send';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Send Permits Reminders Email';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$now = now();
|
|
$startRange = $now->subDays(3)->startOfDay();
|
|
$endRange = $now->copy()->addDays(6)->endOfDay();
|
|
|
|
$reminders = PermitsReminder::whereDate('reminder_date', '>=', $startRange)
|
|
->whereDate('reminder_date', '<=', $endRange)
|
|
->pluck('model');
|
|
|
|
$this->info($this->getTimeStamp() . json_encode($reminders));
|
|
|
|
$users = User::whereIn(
|
|
'email',
|
|
[
|
|
// 'edmond.wuiming2021@gmail.com',
|
|
'anithagurl96@gmail.com'
|
|
]
|
|
)->get();
|
|
|
|
foreach ($users as $user) {
|
|
$this->info($this->getTimeStamp() . 'Reminder email sent to ' . $user->email);
|
|
if (app()->environment('production')) {
|
|
$user->notify(new PermitsReminderEmail($user, $reminders));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getTimeStamp()
|
|
{
|
|
return '[' . Carbon::now()->format('Y-m-d H:i:s') . '] - ';
|
|
}
|
|
}
|