Laravel: how to populate a blade SELECT with values from a where statement
laravel, laravel-4, php
Solution
I found an answer that worked for me:
Use fluent instead of eloquent, which will look something like this:
$client = DB::table('clients')->where('group_id', 1)->lists('name');
return View::make('index', compact('client'));
Then in your view just call it inside blade form tags like this:
{{ Form::select('client_id', $client, Input::old('client_id')) }}
@KyleK, thanks for trying to help.
Problem
I understand you can send values to a select statement like this: Controller: ``` $client = Client::lists('name', 'id'); return View::make('index', compact('client')); ``` And populate this in my view like so: View: ``` {{ Form::select('client_id', $client, Input::old('client_id')) }} ``` But how do I populate only records from Clients where group_id = 1 for example. I tried: ``` $client = Client::lists('name', 'id')->where('group_id', 1)->get(); ``` and ``` $client = Client::lists('name', 'id')->where('group_id','=', 1)->get(); ``` But it doesn't seem to work like that and gives me the error "Call to a member function where() on a non-object" Any ideas on how to make it work?