laravel12.laravel_113
最終投稿日:2026年06月22日
C:\~\laravel_12> php artisan make:command BatchSample
INFO Console command [C:\~\app\Console\Commands\BatchSample.php] created successfully.
C:\~\laravel_12>
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class BatchSample extends Command {
protected $signature = 'app:batch-sample';
protected $description = 'Command description';
public function handle() {
//
}
}
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class BatchSample extends Command {
protected $signature = 'app:batch-sample';
protected $description = 'Command description';
public function handle() {
$path = Storage::disk('local')->path('ftp/hoge.txt');
Storage::disk('ftp')->putFileAs('/', $path, 'hoge.txt');
}
}
<?php
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
<?php
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
Schedule::command('app:batch-sample')->dailyAt('02:00');
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
C:\~\laravel_12> php artisan schedule:list
0 2 * * * php artisan app:batch-sample ......... Next Due: 20 hours from now
C:\~\laravel_12>
『CRON』で設定した時間まで待つのは時間の無駄ですよね。
そこで強制的に『CRON』が発火した状態にするコマンドが以下となります。
php artisan schedule:run
これで、ただちに『~\routes\console.php』が呼ばれます。
しかし今度は、Laravel内の時間設定まで発火するのを待たなくては..orz
スケジュールに設定した時間と、確認した際に表示される《何時間後》がズレてる方いませんか?
『config\app.php』内にある《timezone》を確認してください。それはタイムゾーンの設定が原因です。
ここの値を[UTC]から[Asia/Tokyo]へ変更しましょう。