通过 Artisan 控制台命令访问参数输入
Access Arguments Input via Artisan Console Command
我想 运行 我的命令是这样的
php artisan update:code --code=123
我想从第一个参数中获取代码 - 我似乎无法在 Laravel 网站上找到实现它的方法。
<?php
namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
class updateCode extends Command
{
protected $signature = 'update:code {code}';
protected $description = 'Update Code ... ';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$code = $this->option('code');
$this->info($code);
$user = User::where('type','Admin')->first();
$user->code = bcrypt($code);
$user->active = 1;
$user->save();
$this->info($user);
}
}
我不断收到
The "--code" option does not exist.
我也需要定义我的选项吗?
我怎样才能快速访问第一个参数?
我想 运行 我的命令是这样的
php artisan update:code --code=123
我想从第一个参数中获取代码 - 我似乎无法在 Laravel 网站上找到实现它的方法。
<?php
namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
class updateCode extends Command
{
protected $signature = 'update:code {code}';
protected $description = 'Update Code ... ';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$code = $this->option('code');
$this->info($code);
$user = User::where('type','Admin')->first();
$user->code = bcrypt($code);
$user->active = 1;
$user->save();
$this->info($user);
}
}
我不断收到
The "--code" option does not exist.
我也需要定义我的选项吗?
我怎样才能快速访问第一个参数?