After the Excel output, I want to send an SMS to the person’s mobile number with the date entered in Excel 5 days before that date.
I also used the job command.
Controller.php
public function import(Request $request)
{
Excel::import(new OtherImport, $request->file('file')->store('temp'));
$insuranceData = Other::query()->select('personal_insurance', 'mobile')->get();
$sentMobileNumbers = [];
foreach ($insuranceData as $data) {
$insuranceDate = $data->personal_insurance;
$mobileNumber = $data->mobile;
if (!empty($insuranceDate) && !in_array($mobileNumber, $sentMobileNumbers)) {
try {
$jalaliDate = Jalalian::fromFormat('Y/m/d', $insuranceDate);
$carbonDate = Carbon::create($jalaliDate->getYear(), $jalaliDate->getMonth(), $jalaliDate->getDay());
$smsDate = $carbonDate->subDay(5);
if ($smsDate->isPast()) {
SendSmsJob::dispatch([$mobileNumber]);
$sentMobileNumbers[] = $mobileNumber;
}
} catch (Exception $e) {
dd($e->getMessage());
}
}
}
return back();
}
2
Answers
A solution could be to send a job with a delay to the queue. Then use the
smsDate
variable. I would suggest also setting a time to trigger the sending of the sms at a convenient time for the customer.you need to use
Bur remember that you need to do some changes