LoginSignup
5
6

More than 5 years have passed since last update.

Laravelプロジェクト内のviewsのキャッシュクリアコマンドを追加する

Posted at

ページを表示した際にapp/storage/views直下にキャッシュが溜まっていきますが、
これを削除するコマンドがデフォルトでありませんでしたので追加しました。

方法

キャッシュクリアのコマンドの実装自体はこちらにコードがありましたので、行いません。

なので、これをコマンドとして追加していきますー。

コマンドの追加方法

まずは、app/start/artisan.php内に追加するコマンド名を記述します。

<?php

/*
|--------------------------------------------------------------------------
| Register The Artisan Commands
|--------------------------------------------------------------------------
|
| Each available Artisan command must be registered with the console so
| that it is available to be called. We'll register every command so
| the console gets access to each of the command object instances.
|
*/

Artisan::add(new ViewsCommand);

次に、先ほどのキャッシュクリアコマンドのファイルをapp/commands/ViewsCommand.phpとして
配置します。

これで完了です!簡単ですね〜

実行してみる

あとは、php artisan listでviews:clearが追加されていることを確認して、
php artisan views:clearするとapp/storage/views以下がクリアされているはずです!

他にもartisanコマンドは色々と改造できますので、
http://laravel4.kore1server.com/docs/42/commands
を参考にやってみてください!

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6