0

I'm relatively new to Laravel (and using Laravel 4), but been around PHP and C# a long time. Seems like this should be easy, but I can't find anywhere that tells me how to do this.

In my Controller I get the data from the database and send it to the view like this:

$sections = DB::table('paperSections')->lists('section','id');
return View::make('layouts.publisher.step2', array('sections' => $sections));

in my View, I have the following:

{{ Form::select('sections[]', $sections, '', array('multiple')) }}

which generates a select list like this:

<select multiple="multiple" id="sections" name="sections">
<option value="1">News</option>
<option value="2">Sports</option>
<option value="3">Features</option>
<option value="4">Arts and Entertainment</option>
<option value="5">Technology and Science</option>
<option value="6">Op-Ed</option>
</select>

Lets assume I have a string (e.g. "1,3,5") which represents the multiple options selected previously. How can I re-select those three options using that string?

1 Answer 1

3

Pass array of selected options as 3rd param:

$selected = explode(',', $idsAsString);

Form::select('sections[]', $sections, $selected, ['multiple'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.