2 回答

TA贡献2019条经验 获得超9个赞
发出命令
php artisan make:command UpdateUserNotNew
在该类 app/Console/Commands/UpdateUserNotNew.php 中设置命令名称:
protected $signature = 'cron:update-user-not-new';
根据处理方法:
public function handle()
{
Customer::whereDate('created_at', '>', now()->addDays(7)->toDateTimeString())
->update([
'new_customer_status' => null
]);
}
在 app/Console/Kernel.php 中的schedule()方法下添加以下行:
protected function schedule(Schedule $schedule)
{
$schedule->command('cron:update-user-not-new')->daily(); //<--- this line
}
为了使所有这些工作正常,您必须在服务器上启用 crontab,该信息位于 Laravel 文档中:https://laravel.com/docs/7.x/scheduling#introduction

TA贡献1848条经验 获得超10个赞
您必须将查询放入排队作业中。然后,您可以安排该作业在一周后运行。
这是文档中给出的示例,就在这里:https ://laravel.com/docs/7.x/queues#delayed-dispatching
ProcessPodcast::dispatch($podcast)->delay(now()->addMinutes(10));
ProcessPodcast
工作等级在哪里。我将让您进一步深入文档以了解如何创建作业,但这确实非常简单明了。当然,就您的情况而言,您可能应该这样做now()->addWeek()
而不是now()->addMinutes(10)
.
- 2 回答
- 0 关注
- 112 浏览
添加回答
举报