1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravelのキャッシュクリア系コマンドを一発で行う

Last updated at Posted at 2023-05-28

キャッシュクリア系コマンド

キャッシュクリア系コマンド
ここで紹介されているこの4つを一発で実行したい。

php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear

bashにしようかな。と考えていたけど、Laravel特有のものを使ってみるか、ということでこの記事。

php artisan make:command clearBatch

これ、実行。

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class clearBatch extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:name';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        return 0;
    }
}

こんなのができる。これを改変。
今回は$signaturehandle()を変える

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;

class clearBatch extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:cacheClear';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        Artisan::call('cache:clear');
        Artisan::call('config:clear');
        Artisan::call('route:clear');
        Artisan::call('view:clear');
        $this->info('Cache cleared successfully.');
    }
}

こんな感じ。これを保存して実行。1発で終わる。

zombie@DESKTOP-JLU30CD:~/working/study_Laravel/myapp$ php artisan command:cacheClear
Cache cleared successfully.

引用

株式会社ゆめみ様:Laravel キャッシュクリア系コマンドなど

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?