I want to create a select box like the one below using illuminate\\html :
Controller
$campaignStatus = Campaign::lists('status', 'id');
compact('campaignStatus') will result in [id=>status]; //example [1 => 'pending']
return view('management.campaign.index', compact('campaignStatus'));
View
{!! Form::select('status', $campaignStatus, array('class' => 'form-control')) !!}
Just change your controller to the following:
public function create()
{
$items = Subject::all(['id', 'name']);
return View::make('your view', compact('items',$items));
}
And your view to:
<div class="form-group">
{!! Form::Label('item', 'Item:') !!}
<select class="form-control" name="item_id">
@foreach($items as $item)
<option value="{{$item->item_id}}">{{$item->id}}</option>
@endforeach
</select>
</div>
Hope this will solve your problem
Many has been said already but keep in mind that there are a times where u don't want to output all the records from the database into your select input field ..... Key example I have been working on this school management site where I have to output all the noticeboard categories in a select statement. From my controller this is the code I wrote
Noticeboard:: groupBy()->pluck('category')->get();
This way u get distinct record as they have been grouped so no repetition of records