I just setup a cron job for a laravel project I’m currently working on. This is the handle function in my command.
public function handle()
{
Log::info("PayoutList Cron started!");
$tradersToPay = Investments::select('id', 'monthly_roi')
->where(DB::raw('CURDATE()'), '<=', 'end_date')
->where(DB::raw('DAY(CURDATE())'), '=', DB::raw('DAY(start_date)'))
->where('status', '=', 2)
->get();
foreach ($tradersToPay as $payout){
$row = [
'investment_id' => $payout->id,
'roi' => $payout->monthly_roi,
#'created_at' => date('Y-m-d H:i:s')
];
Payouts::create($row);
}
#$this->info('PayoutList Cron command executed successfully');
Log::info("PayoutList Cron command executed successfully");
}
I have schedule this command to run daily at midnight and it only shows the Log message in the log files which means the command executed but the query in between is not working on my cpanel but working on my windows local server. I need help on this.
$schedule->command('payoutlist:cron')
->dailyAt('02:30')
->timezone('Africa/Lagos');
My host only allowed to set this on the cron job which still works fine
*/5 * * * * /usr/local/bin/php /directorty/artisan schedule:run >> /dev/null 2>&1
I’m using Laravel 5.8
2
Answers
You Are using Raw query try using eloquent that will be for sure working , or compare DB version between local and online server
instead of DB::raw
use somethin like this : where(‘end_date’, ‘>=’, date(‘Y-m-d’).’ 00:00:00′));
The issue stems from this line:
Laravel expects the third parameter to be a value, so it’s passing
end_date
as a string instead of a column name. Since you’re not passing any actual values, turn the whole where in a raw query: