laravel command
简单使用
laravel command
简单使用
laravel command
简单使用
command
简单使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| php artisan make:command foo protected $signature = 'foo'; protected $description = 'foo class Command description'; php artisan foo
php artisan list
<?php namespace App\Console\Commands; use Illuminate\Console\Command;
class foo extends Command { protected $signature = 'foo'; protected $description = 'foo class Command description';
public function __construct() { parent::__construct(); }
public function handle() { echo "hello foo "; } }
|
在一个 commands
文件中执行对应的方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| protected $signature = 'command {foo}'; php artisan command bar
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class foo extends Command { protected $signature = 'command {foo}'; protected $description = 'foo class Command description';
public function __construct() { parent::__construct(); }
public function handle() { $method = $this->argument('foo'); if (method_exists($this, $method)) { $this->$method(); echo "执行完成\n"; }else{ echo "${method} is not exists\n"; } }
public function bar() { echo "bar"; } }
|

confirm
1 2 3 4 5
| if ($this->confirm("确认要执行吗?")) { exit("开始执行"); }else{ exit('停止执行'); }
|
官方commands