我有一个Laravel 9项目。我需要通过Cron运行一些作业。根据文档,我已经更新了app/console/Kernel.php
,如下所示(测试更新通知表):
namespace App\Console;
use App\Models\notification;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\DB;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->call(function () {
$result = notification::where('id', 1)
->update(['read' => 1]);
$notification = new notification([
'client_id' => 3,
'user_id' => 2,
'client_post_id' => 750,
'create_user_id' => 3,
'notification' => ' System has created a notification'
]);
$ok = $notification->save();
})->everyMinute();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
当我运行php artisan schedule:list
时,我确实看到cron作业正在运行:
Home@MacBook-Air cota % php artisan schedule:list
* * * * * Closure at: app/Console/Kernel.php:29
............................................ Next Due: 42 seconds from now
但是,我没有看到数据库表中有任何变化(当我通过tinker在terminal中运行这些命令时,它工作正常,所以命令很好)
是否有任何我错过了或我需要配置的东西,使写入数据库通过Cron作业。
另外,在哪里可以看到cron错误?
1条答案
按热度按时间bjp0bcyl1#
你可使用
php工匠时间表:工作
Artisan命令。此命令将在前台运行,并每分钟调用一次调度程序,直到您终止此命令