Skip to content

Instantly share code, notes, and snippets.

@wedojava
Created March 25, 2015 09:59
Show Gist options
  • Save wedojava/41296a19a759a57c3d6d to your computer and use it in GitHub Desktop.
Save wedojava/41296a19a759a57c3d6d to your computer and use it in GitHub Desktop.
用laravel5做下拉列表,列表内容从数据库读取
放个例子:
视图:{!!Form::select('difficulty', $difficulties)!!}
控制器:
public function edit($id)
{
return view('admin.questions.edit')
->withQuestion(Question::find($id))
->withDifficulties(Difficulty::lists('name', 'id'));
}
关键问题在于这一句:Difficulty::lists('name', 'id')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment