Support the ongoing development of Laravel.io →
Forms Database Eloquent
Last updated 2 years ago.
0

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) }}

Last updated 2 years ago.
0

Thanks. I'll try it.

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kenold kenold Joined 24 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.