Laravel lists for select/dropdown
Populate a select box with the id & name of everything in a table (except the current item).
// Controller
public function edit($id)
{
$group = $this->group->find($id);
// Get a list of other groups, to select as the parent of this group
$group_list = [''=>'Please select] + Group::where('id', '!=', $id)->lists('name', 'id');
return View::make('groups.edit', compact('group', 'group_list'));
}
// View
<li>
{{ Form::label('parent_id', 'Group:') }}
{{ Form::select('parent_id', $group_list) }}
</li>
Written by Dave Townsend
Related protips
2 Responses
nice one
over 1 year ago
·
Great tip thanks Dave, was looking for something as simple as that!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Dropdown
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#