class SendLostwillEmailsController extends Controller
{
public function runCommand()
{
return $this->getAllLostWill();
}
protected function getAllLostWill()
{
try {
$status = false;
$newMailSetting = new ChangeMailSettings();
$getToday = Carbon::now()->format('Y-m-d');
$getLast7day = Carbon::now()->subDays(7)->format('Y-m-d');
$lostwill = LostWill::select('id', 'lost_first_name', 'lost_last_name', 'lost_dod', 'user_id')->whereBetween('created_at', [$getLast7day, $getToday])->get();
if (!$lostwill->isEmpty()) {
$listOfEmails = $this->getEmailList($lostwill->pluck('user_id'));
$newMailSetting->sendMail();
$listChunkEmail = array_chunk($listOfEmails['emails'], 550, false);
$i = 0;
$countSentMail = 0;
while ($i < count($listChunkEmail)) {
Notification::route('mail', 'info@lostwillregister.com.au')->notify(new SendLostwillMarketingEmail($listChunkEmail[$i], $lostwill));
$countSentMail = ($countSentMail + count($listChunkEmail[$i]));
$i++;
}
//$listChunkEmail[$i]
Log::channel('marketing_mail')->info('total email sent:' . $countSentMail);
$newMailSetting->setDefault();
$status = true;
} else {
$status = false;
Log::channel('marketing_mail')->info("lost will not registers for yesterday's date");
}
return $status;
} catch (Exception $e) {
return false;
Log::channel('marketing_mail')->info($e->getMessage());
}
}
I want to run getAllLostWill()
in crontab. This function get all the lost will for the past 7 days and sends a mail. The file path of SendLostwillEmailsController class is lost-will-register\app\Http\Controllers
Currently, in my crontab I have this:
GNU nano 4.8 /tmp/crontab.qrUExv/crontab
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
25 10 * * * cd /var/www/lost-will-register && php artisan marketing:startCampaign >> /dev/null 2>&1
00 16 * * * cd /var/www/lost-will-register && php artisan delete:files >> /dev/null 2>&1
25 10 * * * cd /var/www/australian-will-register && php artisan reminder:annualwillregistration >> /dev/null 2>&1
00 00 * * 4 cd /var/www/lost-will-register-nz && php artisan marketing:startCampaign >> /dev/null 2>&1
00 16 * * * cd /var/www/lost-will-register-nz && php artisan delete:files >> /dev/null 2>&1
would this be right command to run the function getAllLostWill() 00 01 1 1 * cd /var/www/lost-will-register && php artisan reminder:getAllLostWill >> /dev/null 2>&1
?
I am new to crontab, so I don't know much; however, I assume you need to put the command first, as in time 00 00 ** **
, and then the path to the file I mentioned above. I am not sure how to put it all together to send a mail every week on Thursday at 1 pm, so by running the getAllLostWill() function, which sends the mail