我在 App/Console/Kernel.php
任务调度中有以下代码片段:
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$tours = Tour::all();
$date = date("Y/m/d");
$week = strtotime("+1 week", $date);
$exploded = explode("/", $week);
foreach ($tours as $tour) {
foreach($tour->datePrice as $d) {
if ($d->isNotEmpty()) {
DB::table('dateprice')
->where('tour_id', '=', $tour->id)
->where('start_day', '=', $explode[0])
->where('start_month', '=', $explode[1])
->where('start_year', '=', $explode[2])
->delete();
}
}
}
}
})->everyMinute();
}
我正在尝试通过检查游览的开始日期,在调度程序的帮助下从表中删除记录。 我每分钟都在运行这个计划来检查它是否有效。不幸的是,代码没有做任何事情。我的代码有什么错误吗??
如果有人能告诉我如何在 laravel 中测试调度器,我将不胜感激。
最佳答案
你只需要在你的服务器上添加以下Cron条目,它就会自动执行schedule:run artisan命令。
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
使用以下命令启动任务调度-
php artisan schedule:run
当您关闭 cmd
时,此命令将停止工作可以关注laravel doc .
关于php - 在 laravel 中测试调度器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47505441/