Console command with choice using eloquent
I'm trying to show choice option using eloquent.
So far I do this but it doesn't work for non-unique names. Is there a better way of doing this?
$industries = Industry::get();
$choice = $this->choice('Which industry?', $industries->pluck('name')->toArray());
$industry = $industries->firstWhere('name', $choice);
Well, because it's non-unique, it's kinda bad UX to show:
Which industry?
IT
IT
IT
I, as a user, would have no idea why it's the same line written 3 times. I recommend adding a bit more info, making it unique, like:
Whch industry?
IT (#123)
IT (#22424)
IT (#industry-id-here)
Please or to participate in this conversation.