spatie / blender

The Laravel template used for our CMS like projects
https://freek.dev/on-open-sourcing-blender
876 stars 148 forks source link

Added multiselect form field for associated models #421

Closed AlexVanderbist closed 7 years ago

AlexVanderbist commented 7 years ago

associatedModelsSelect will build a multiselect form field based on a relation on the form's model.

For example:

{{ html()->modelForm($user, 'POST')->open() }}

    {{ html()->formGroup()->associatedModelsSelect('projects', 'Associated projects');

{{ html()->closeModelForm() }}

This will build a form for the user model with a multiselect element containing all Projects as options and automatically select any already associated projects.

You can also specify a custom collection of options and the name of the property used for the <option> labels:

{{ html()->modelForm($user, 'POST')->open() }}

    {{ html()->formGroup()->associatedModelsSelect('projects', 'Associated projects', Project::active()->get(), 'title');

{{ html()->closeModelForm() }}