[フレーム]
Last Updated: February 25, 2016
·
4.696K
· maumagau

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>

2 Responses
Add your response

nice one

over 1 year ago ·

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

over 1 year ago ·

AltStyle によって変換されたページ (->オリジナル) /