php artisan optimizeはなんとなくいい感じに最適化してくれるコマンド、ではない ==== ``` php artisan optimize ``` 意味も分からず誰かから教わったことの真似しかできない人はフレームワーク内部のコードを調べる癖を付けるべき。 https://github.com/laravel/framework/blob/11.x/src/Illuminate/Foundation/Console/OptimizeCommand.php optimizeはキャッシュコマンドをまとめて実行しているだけのコマンドでしかない。 ```php collect([ 'config' => fn () => $this->callSilent('config:cache') == 0, 'events' => fn () => $this->callSilent('event:cache') == 0, 'routes' => fn () => $this->callSilent('route:cache') == 0, 'views' => fn () => $this->callSilent('view:cache') == 0, ])->each(fn ($task, $description) => $this->components->task($description, $task)); ``` 「開発環境では絶対にキャッシュコマンドを使ってはいけない」のでoptimizeコマンドも使ってはいけない。 間違って使ってしまったらoptimize:clearでキャッシュを削除する。 ``` php artisan optimize:clear ``` optimize:clearは逆でまとめてキャッシュを削除しているだけのコマンド。 ```php collect([ 'cache' => fn () => $this->callSilent('cache:clear') == 0, 'compiled' => fn () => $this->callSilent('clear-compiled') == 0, 'config' => fn () => $this->callSilent('config:clear') == 0, 'events' => fn () => $this->callSilent('event:clear') == 0, 'routes' => fn () => $this->callSilent('route:clear') == 0, 'views' => fn () => $this->callSilent('view:clear') == 0, ])->each(fn ($task, $description) => $this->components->task($description, $task)); ``` https://github.com/laravel/framework/blob/11.x/src/Illuminate/Foundation/Console/OptimizeClearCommand.php