mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
add cron job command to send permits reminder
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Notifications;
|
||||
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class PermitsReminderEmail extends AbstractEmail
|
||||
{
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
private $reminders;
|
||||
|
||||
/**
|
||||
* SendResetPasswordEmail constructor.
|
||||
* @param User $user
|
||||
* @param PasswordReset $attempt
|
||||
*/
|
||||
public function __construct(User $user, $reminders)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->reminders = $reminders;
|
||||
}
|
||||
|
||||
public function toMail()
|
||||
{
|
||||
return (new MailMessage)
|
||||
->subject('Permits Renew Remidner Email')
|
||||
->view('emails.reminder.permits_reminder', ['user' => $this->user, 'reminders' => $this->reminders]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Classes\Notifications\PermitsReminderEmail;
|
||||
use App\Models\PermitsReminder;
|
||||
use App\Models\User;
|
||||
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(json_encode($reminders));
|
||||
|
||||
$users = User::whereIn('email', ['edmond.wuiming2021@gmail.com'])->get();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$this->info('Reminder email sent to ' . $user->email);
|
||||
$user->notify(new PermitsReminderEmail($user, $reminders));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
@extends('emails.layout.base')
|
||||
|
||||
@section('content')
|
||||
<h4 style="font-size: 1em;">Hello, {{ $user->first_name.' '.$user->last_name }}</h4>
|
||||
<p style="font-size: 0.9em">The permits listed below either expiring within the period of the next 3 days or have already expired 3 days ago.</p>
|
||||
|
||||
<ul>
|
||||
@foreach($reminders as $reminder)
|
||||
<li>{{ $reminder }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endsection
|
||||
Reference in New Issue
Block a user