qippzg
Last Updated: February 25, 2016
·
3.37K
· maumagau
Dave

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>
Say Thanks
Respond

2 Responses
Add your response

13181

nice one

over 1 year ago ·
16771
Mskk0di0 normal

Great tip thanks Dave, was looking for something as simple as that!

over 1 year ago ·