adamwathan / bootforms

Rapid form generation with Bootstrap 3 and Laravel.
MIT License
417 stars 103 forks source link

Select multiple binding #128

Closed breakeryouko closed 7 years ago

breakeryouko commented 7 years ago

Hi all, I create a multiple select list in the form, but I want to bind it when the user is updating. Is there any method to pass the selected array?

adamwathan commented 7 years ago

Yep, as long as the object you bind has a property matching the select field's name and has an array of values in that property, it should bind for you:

{!! BootForm::open() !!}

    {!! BootForm::bind($user) !!}}

    {!! BootForm::select('foods', ['fish' => 'Fish', 'chips' => 'Chips', 'candy' => 'Candy'])->multiple() !!}

{!! BootForm::close() !!}
$user = new User([
    'foods' => ['fish', 'candy']
]);