Laravelでタスクスケジュール機能を利用してクイズがランダムに更新されるという処理を作ったのですが、タスクスケジュールが正常に動いているはずなのに全く変化がありません。TimeQuiz.phpのhandle()の記述がおかしいのでしょうか?
同じプログラムをController.phpに書いた場合普通に動きます。
php artisan schedule:runを実行した結果
Running scheduled command: '/usr/bin/php' 'artisan' command:quiz > '/dev/null' 2>&1
TimeQuiz.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Quiz;
class TimeQuiz extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:quiz';
/**
* The console command description.
*
* @var string
*/
protected $description = 'TimeQuiz';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$quiz = Quiz::with('answer')
->inRandomOrder()
->get();
return $quiz;
}
}
Kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
'App\Console\Commands\TimeQuiz'
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('command:quiz')
->everyMinute()
->onSuccess(function () {
Log::info('成功');
});
}