multiSelect
Creates multiple select input.
FormItem::multiSelect('categories', 'Categories')
Providing Data
With array:
->list(['First', 'Second', 'Third])
With enum (use array values as keys):
->enum(['First', 'Second', 'Third])
With class:
->list(\Foo\MyModel::class)
MyModel
must implement public static function getList()
and return array.
Providing Selected Items
->value('categories.article_id')
Saving Data
Create new mutator method in your model. Here is an example:
public function setCategoriesAttribute($categories)
{
$this->categories()->detach();
if ( ! $categories) return;
if ( ! $this->exists) $this->save();
$this->categories()->attach($categories);
}
categories()
method creates belongs-to-many
relation in this case.