---
# System prepended metadata

title: laravel command
tags: [Laravel]

---

# laravel command


https://blog.johnsonlu.org/laravel-artisan/

https://www.youtube.com/watch?v=-r3WnYy7g48
## 用命令跑所有想跑的class
https://www.youtube.com/watch?v=aZahY16mKpY

## 主要註冊

make:command 
--command如果沒有打還是可以去$signature更改

基本上都會跑handle
所以會都在這邊使用service
```
<?php

namespace App\Console\Commands;

use App\Services\Admin\Banner\BannerService;
use Illuminate\Console\Command;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '變更banner上架狀態';

    /**
     * BannerService.
     *
     * @var BannerService
     */
    private $bannerService;

    /**
     * Create a new command instance.
     */
    public function __construct(BannerService $bannerService)
    {
        parent::__construct();

        $this->bannerService = $bannerService;
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->bannerService->validStatus();
    }
}
```
## 輸入參數
$this->argument()
![](https://i.imgur.com/b6780i2.png)
![](https://i.imgur.com/KlIfK76.png)
可以選擇輸入
沒輸入就 ?? Str::random(20)之類的

那如果要讓他mull呢
-- =
![](https://i.imgur.com/0BRWU2f.png)
![](https://i.imgur.com/UH5lGtI.png)

獲取參數
![](https://i.imgur.com/JMc4IJ5.png)
![](https://i.imgur.com/BNO1tBa.png)
![](https://i.imgur.com/nnxhKrT.png)

## 進度條

https://www.youtube.com/watch?v=H4mxFUlR1vc&ab_channel=Laratips

createProgressBar()
![](https://i.imgur.com/bAowtSc.png)
先創立
然後start
再跌代裡面用 advance
結束在用 finish

###### tags: `Laravel`