Struggling with the problem in Laravel 4, in the form of editing the contact model, I can get all the current values โโof the fields, except those indicated in the multiple choice, which should establish a connection with another model of "company". This is a many-to-many relationship. I get a list of companies, but no one gets selected, even if there is a relationship.
Here is my edit form:
{{ Form::model($contact, array('route' => array('crm.contacts.update', $contact->id), 'id' => 'edit-contact')) }} <div class="control-group"> {{ Form::label('first_name', 'First Name', array( 'class' => 'control-label' )) }} {{ Form::text('first_name') }} </div> <div class="control-group"> {{ Form::label('last_name', 'Last Name', array( 'class' => 'control-label' )) }} {{ Form::text('last_name') }} </div> <div class="control-group"> {{ Form::label('email', 'Company Email', array( 'class' => 'control-label' )) }} {{ Form::text('email') }} </div> <div class="control-group"> {{ Form::label('company_ids', 'Company', array( 'class' => 'control-label' )) }} {{ Form::select('company_ids[]', $companies, array('',''), array('multiple'), Input::old('company_ids[]')) }} </div> {{ Form::close() }}
My controller:
public function edit($id) { $contact = Contact::find($id); $company_options = Company::lists('name', 'id'); return View::make('crm.contacts.edit') ->with('contact', $contact) ->with('companies', $company_options);; }
Any ideas on how to have a multiple select box pre-populated with existing values?
thanks
source share