Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Docs
  • Loading branch information
pascalbaljet committed Dec 22, 2020
commit 5b51e1ebe0252dcc1923c611b6ec1519b307e811
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ If you want a select element where multiple options can be selected, add the `mu
<x-form-select name="country_code" :options="$countries" multiple :default="['be', 'nl']" />
```

#### Using Eloquent relationships

This package has built-in support for `BelongsToMany`, `MorphMany` and `MorphToMany` relationships. To leverage this feature, you must add both the `multiple` and `many-relation` attribute to the select element.

In the example below, you can attach one or more tags to the bound video. By using the `many-relation` attribute, it will correctly retrieve the selected options from the database.

```blade
<x-form>
@bind($video)
<x-form-select name="tags" :options="$tags" multiple many-relation />
@endbind
</x-form>
```

### Checkbox elements

Checkboxes have a default value of `1`, but you can customize it as well.
Expand Down
6 changes: 1 addition & 5 deletions src/Components/FormSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ public function isSelected($key): bool
return false;
}

$haystack = $this->selectedKey instanceof Arrayable
? $this->selectedKey->toArray()
: $this->selectedKey;

return in_array($key, Arr::wrap($haystack));
return in_array($key, Arr::wrap($this->selectedKey));
}
}