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.
-`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.
72
-
-`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.
73
-
-`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.
74
-
-`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.
75
-
-`withDataAttribute(string $attribute, mixed|callable $value)`: This method allows you to add a data attribute to each option.
118
+
119
+
-`withLabel(string|callable $label)`: This method allows you to customize the label for each option. A string will be
120
+
used as the collection field from which the label will be generated, while a callable will be used to generate the
121
+
label.
122
+
-`withValue(string|callable $value)`: This method allows you to customize the value for each option. A string will be
123
+
used as the collection field from which the value will be generated, while a callable will be used to generate the
124
+
value.
125
+
-`withSelected(mixed|callable $selected)`: This method allows you to customize the selected options. Can be
126
+
a `string`, `int`, an array of `string`/`int`, a `model` or a callable that returns a boolean value.
127
+
-`withDisabled(mixed|callable $disabled)`: This method allows you to customize the disabled options. Can be
128
+
a `string`, `int`, an array of `string`/`int`, a `model` or a callable that returns a boolean value.
129
+
-`withDataAttribute(string $attribute, mixed|callable $value)`: This method allows you to add a data attribute to each
130
+
option.
76
131
-`withClass(string $class)`: This method allows you to add a class to each option.
77
-
-`toSelectItems()`: This method converts the selectable collection to an array of selectable items. Useful for Ajax responses or SPA.
132
+
-`toSelectItems()`: This method converts the selectable collection to an array of selectable items. Useful for Ajax
133
+
responses or SPA.
78
134
-`toSelectOptions()`: This method converts the selectable collection to an HTML select options string.
79
-
-
135
+
- Some of the methods from `Illuminate\Support\Collection` are also available including `groupBy()`.
136
+
137
+
> <small><strong>Note:</strong> Writing queries within blade templates is not recommended. This is only for simplifying
0 commit comments