Hello, how to send value for options in dropdown list from array, or how to convert output this code to associative array
$Aagents=array();
foreach($agents as $agent)
{
array_push($Aagents,$agent->first_name." ".$agent->last_name);
}
more details for output this code after send to dropdownlist in view
<option value="0" selected="selected">Main Agent</option>
<option value="1" >Sub Agent</option>
I need send value in options from id_user not index how this
Thanks
Basic PHP I guess ?
$Aagents=array();
foreach($agents as $agent)
{
$agents[$agent->index] = $agent->first_name." ".$agent->last_name;
}
$agents = Agent::lists($value, $key);
// view
{{ Form::select('agent_id', $agents) }}
Not quite what pogachar said. If you already have a collection, just do the following:
{{ Form::select('agent_id', $agents->lists('id', 'first_name');
Or, if you need the full name - write a getter on the model that retrieves them both as name(), then you can use name as the last argument in the lists() call.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community