我做完了定时任务,但是好像只有每次执行php artisan schedule:run
才会执行写在kernel里的shcehdule任务?要怎么让他一直默认执行?
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$allExpiredInvitations = User::where('is_active',false)->where('confirm_token', '!=', 'expired')->get();
$now = Carbon::now();
foreach ($allExpiredInvitations as $entry) {
$update = $entry->created_at;
$diff = $now->diffInMinutes($update);
if ($diff >= 2) {
$entry->outdateToken();
$entry->save();
}else{
// do nothing
}
}
})->everyMinute()->runInBackground();
}