【发布时间】:2019-10-17 22:07:38
【问题描述】:
我想像这样运行我的命令
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);
}
}
我一直得到
“--code”选项不存在。
我也需要定义我的选择吗?
我怎样才能快速访问第一个参数?
【问题讨论】:
标签: php laravel laravel-5 laravel-5.7 laravel-artisan