我想做一种形式的用户帖子。该表格将包含帖子标题,帖子说明和帖子过期时间。我将在数据库列中存储帖子的过期时间。表列将是:

id | user_id | post_title | post_description | post_status | post_expire_time


假设用户已指定4小时的过期时间。 post_status默认为not-expired。 4小时后,post_status将转换为expired。如何在Laravel应用中做到这一点?

最佳答案

您需要自动更新行的内容。幸运的是,Laravel为此提供了Task Scheduling

要使用它,您必须创建一(1)个cronjob,它每分钟运行一次。然后,您可以在代码中配置计划。像这样:

// In the App\Console\Kernel class:

protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {
        // Update your post_status here
    })->hourly();
}

关于php - PHP Laravel表单接受日/小时输入并设置到期时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36909766/

10-12 04:53