Make a form macro. Untested and just a concept, you will probably want to make form macro service provider that does this stuff easier and use of repositories etc.
Form::macro('companies', function($name, $value = null, array $options= array())
{
$list = Comany::all()->list('company_name', 'id');
return Form::select($name, $list, $value, $options);
});
// Usage in blade template. (If you binded the model)
{{ Form::companies('company_id') }}
// Usage in blade template. (Specifying value)
{{ Form::companies('company_id', $model->company_id) }}
Hi, You could also try this. In your customer controller:
public function edit($id)
{
$customer = Customer::findOrFail($id);
$company = Company::lists('company_name','id');
return View::make('customer.edit', compact('customer', 'company'));
}
then in your views:
{{Form::label('company_id','Company Name')}}
{{ Form::select('company_id', $company, $customer->company_id, array('class' => 'form-control') ) }}
Hope it helps
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community