Laravel/Symfonyがコンソールの一部として提供する「選択」機能を使用しようとしています。数値インデックスに関しては問題があります。Laravel choiceコマンドの数値キー
私は文字列の値を表示するが実際に文字列ではなく関連付けられたIDを返すという意味で、HTML select要素の動作をシミュレートしようとしています。
例 - 残念ながら$選択肢は常に名前ですが、私はID
<?php
namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
class DoSomethingCommand extends Command
{
protected $signature = 'company:dosomething';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$choice = $this->choice("Choose person", [
1 => 'Dave',
2 => 'John',
3 => 'Roy'
]);
}
}
回避策たい - 私は人のIDの前に付ける場合、それは動作しますが、そこに期待していたが、別の方法であるか、これはただの制限でありますライブラリの?
<?php
namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
class DoSomethingCommand extends Command
{
protected $signature = 'company:dosomething';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$choice = $this->choice("Choose person", [
"partner-1" => 'Dave',
"partner-2" => 'John',
"partner-3" => 'Roy'
]);
}
}
「$ this」とは何ですか? –