You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://packagist.org/packages/ringlesoft/laravel-selectable)
The method `toSelectable` is used to convert the collection into a `Selectable` object. The `Selectable` object has several methods that allow you to customize the options and their properties.
69
+
#### Method parameters
70
+
71
+
-`label`: The name of the field to be used as the label for the option. If a closure is provided, the result of the
72
+
closure will be used as the label. Default is `name`.
73
+
-`value`: The name of the field to be used as the value for the option. If a closure is provided, the result of the
74
+
closure will be used as the value. Default is `id`.
75
+
-`selected`: The value of the item to be used as the selected option. Can be value, array of values or closure.
76
+
-`disabled`: The value of the item to be used as the disabled option. Can be value, array of values or closure.
77
+
78
+
### 3. Advanced Usage
79
+
80
+
This package allows building of select options from a `Selectable` object using method chaining.
81
+
The method `toSelectable()` is used to convert the collection into a `Selectable` object. The `Selectable` object has
82
+
several methods that allow you to customize the options and their properties. The `toSelectOptions` method is used to
83
+
convert the `Selectable` object into html select options.
-`toSelectable()`: This method returns the current selectable object.
85
-
-`withLabel(string|callable $label)`: This method allows you to customize the label for each option. A string will be used as the collection field from which the label will be generated, while a callable will be used to generate the label.
86
-
-`withValue(string|callable $value)`: This method allows you to customize the value for each option. A string will be used as the collection field from which the value will be generated, while a callable will be used to generate the value.
87
-
-`withSelected(mixed|callable $selected)`: This method allows you to customize the selected options. Can be a `string`, `int`, an array of `string`/`int`, a `model` or a callable that returns a boolean value.
88
-
-`withDisabled(mixed|callable $disabled)`: This method allows you to customize the disabled options. Can be a `string`, `int`, an array of `string`/`int`, a `model` or a callable that returns a boolean value.
100
+
101
+
This will generate a multi-select dropdown with options for all users, using the `id` field as the `value`, and a
102
+
combination of the `first_name` and `last_name` fields as the `label`. Options with IDs `2` and `3` will be selected by
103
+
default,
104
+
and options with an '`inactive`' `status` will be disabled. A '`data-hidden`' attribute will be added to options with
105
+
a `status`
106
+
other than '`active`', and a custom class '`form-option custom`' will be applied to all options.
0 commit comments