我在mysql数据库中有一个表,我想在每个午夜设置该表中的一行为false。
我该怎么做呢?
创建一个控制器函数并在午夜执行。假设有ScheduleController
class ScheduleController extends Controller {
public function resetDataBase()
{
//write query here to change the table row.
//You may use raw queries
}
}
然后在App'Console'Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->call(''App'Http'Controllers'ScheduleController@resetDataBase')
->dailyAt('00:00');
}
在托管应用程序的服务器上,必须设置crontab
条目
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
您可以设置一个任务在午夜运行,并在该任务中做任何您想做的事情。查看任务调度文档