@@ -44,7 +44,14 @@ private function _shouldSelect(mixed $item, int|string|null $index = null): bool
4444 return (bool )call_user_func ($ this ->_selected , $ item , $ index );
4545 }
4646
47- $ optionValue = ($ this ->_value instanceof Closure) ? call_user_func ($ this ->_value , $ item , $ index ) : (is_object ($ item ) ? ($ item ->{$ this ->_value } ?? "" ) : $ item );
47+ if ($ this ->_value instanceof Closure) {
48+ $ optionValue = call_user_func ($ this ->_value , $ item , $ index );
49+ } else {
50+ $ optionValue = (is_object ($ item ) ? ($ item ->{$ this ->_value } ?? "" ) : $ item );
51+ if (is_array ($ item )) {
52+ $ optionValue = $ item [$ this ->_value ] ?? reset ($ item );
53+ }
54+ }
4855 if (is_object ($ this ->_selected )) {
4956 return ((string )$ this ->_selected ->{$ this ->_value } === (string )$ optionValue );
5057 }
@@ -83,6 +90,9 @@ private function _shouldDisable(mixed $item, int|string|null $index = null): boo
8390 $ lineValue = call_user_func ($ this ->_value , $ item , $ index );
8491 } else {
8592 $ lineValue = (is_object ($ item ) ? ($ item ->{$ this ->_value } ?? "" ) : $ item );
93+ if (is_array ($ item )){
94+ $ lineValue = $ item [$ this ->_value ] ??reset ($ item );
95+ }
8696 }
8797
8898 if (is_object ($ this ->_disabled )) {
@@ -143,11 +153,17 @@ private function _generateOptions(Collection $collection, int $lastIndex = 0): s
143153 $ optionLabel = call_user_func ($ this ->_label , $ item , $ index );
144154 } else {
145155 $ optionLabel = is_object ($ item ) ? ($ item ->{$ this ->_label } ?? "N/A " ) : ($ item );
156+ if (is_array ($ item )) {
157+ $ optionLabel = $ item [$ this ->_label ] ?? array_keys ($ item )[0 ];
158+ }
146159 }
147160 if ($ this ->_value instanceof Closure) {
148161 $ optionValue = call_user_func ($ this ->_value , $ item , $ index );
149162 } else {
150163 $ optionValue = is_object ($ item ) ? ($ item ->{$ this ->_value } ?? "" ) : $ item ;
164+ if (is_array ($ item )) {
165+ $ optionValue = $ item [$ this ->_value ] ?? reset ($ item );
166+ }
151167 if (is_string ($ index ) && is_string ($ item )) {
152168 $ optionValue = $ index ;
153169 }
@@ -219,9 +235,22 @@ public function toSelectOptions(): string
219235 public function toSelectItems (): Collection
220236 {
221237 return $ this ->_collection ->map (function ($ item , $ index ) {
238+ if ($ this ->_label instanceof Closure) {
239+ $ optionLabel = call_user_func ($ this ->_label , $ item , $ index );
240+ } else {
241+ $ optionLabel = is_object ($ item ) ? ($ item ->{$ this ->_label } ?? "N/A " ) : ($ item );
242+ }
243+ if ($ this ->_value instanceof Closure) {
244+ $ optionValue = call_user_func ($ this ->_value , $ item , $ index );
245+ } else {
246+ $ optionValue = is_object ($ item ) ? ($ item ->{$ this ->_value } ?? "" ) : $ item ;
247+ if (is_string ($ index ) && is_string ($ item )) {
248+ $ optionValue = $ index ;
249+ }
250+ }
222251 return [
223- 'value ' => $ item ->{ $ this -> _value } ?? "" ,
224- 'label ' => $ index ,
252+ 'value ' => $ optionValue ,
253+ 'label ' => $ optionLabel ,
225254 'isSelected ' => $ this ->_shouldSelect ($ item , $ index ),
226255 'isDisabled ' => $ this ->_shouldDisable ($ item , $ index ),
227256 'data ' => $ this ->_getDataAttributes ($ item , $ index ),
0 commit comments