【问题标题】:Laravel Command argument returns keyvalue pair insted of valueLaravel 命令参数返回键值对而不是值
【发布时间】:2019-12-06 11:33:28
【问题描述】:

我已经通过php artisan make:command SomeCommand 生成了 Laravel artisan 命令。这是整个命令类SomeCommand

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class SomeCommand extends Command{
    protected $signature = 'Call:SomeCommand {phone="8980131488"} {name="Kiran Maniya"}';

    protected $description = 'This is a buggy Command';

    public function __construct(){
        parent::__construct();
    }

    public function handle(){
        $args = $this->arguments();
        $this->info($args['phone'].' '.$args['name']);
    }
}

问题是,当我通过php artisan Call:SomeCommand phone="8980151878" name="Anubhav Rane" 调用命令时。它将密钥对值的参数输出为name=Anubhav Ranephone=8980151878。它应该只输出值。 我还尝试通过$this-&gt;argument('phone')$this-&gt;argument('name') 捕获单个值,但它的输出仍然相同。

【问题讨论】:

    标签: php laravel arguments command key-value


    【解决方案1】:

    您传递参数的方式不正确。试试这个:

    php artisan Call:SomeCommand 8980151878 'Anubhav Rane'
    

    【讨论】:

      猜你喜欢
      • 2020-01-10
      • 1970-01-01
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      • 2017-09-03
      • 2023-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多