Php 如何使用Laravel和Forge执行CronJob
我需要在forge Laravel中执行一个CronJob,但是当我将时间设置为每天时,这个作业不会在forge的午夜运行,但是当我将forge中的时间设置为每分钟时,它就工作了Php 如何使用Laravel和Forge执行CronJob,php,laravel,cron,Php,Laravel,Cron,我需要在forge Laravel中执行一个CronJob,但是当我将时间设置为每天时,这个作业不会在forge的午夜运行,但是当我将forge中的时间设置为每分钟时,它就工作了 <?php namespace App\Console; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use App\Models\User; c
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Models\User;
class Kernel extends ConsoleKernel
{
protected $commands = [
\App\Console\Commands\Inspire::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->call(function() {
$users = User::all();
foreach($users as $user) {
if($user->remaining_days == 0 && $user->user_level != 4)
$user->user_level = 0;
else
$user->remaining_days = $user->remaining_days - 1;
$user->save();
}
})->daily();
}
protected function commands()
{
require base_path('routes/console.php');
}
}
您可以使用子句代替->daily()
如果您想在午夜运行它,我想您还应该检查服务器的时区,以确保将正确的时间传递到->dailyAt()
->dailyAt('12:00');