[9.x] Added callable support to operatorForWhere on Collection#41414
Conversation
Added `callable` support to `operatorForWhere`.
Currently only Collection methods `where` and `whereFirst` are used without `callable` support.
Adding callable to `operatorForWhere` allow complex usages as:
```php
$city = $cities->firstWhere(fn ($city) => $city->state->available && ($city->state->id === $stateId));
```
or
```php
$state = $states->firstWhere(fn ($state) => (bool)$state->cities->firstWhere('id', $cityId));
```
|
Hmm, what all methods does this affect? |
|
Only Method framework/src/Illuminate/Collections/Traits/EnumeratesValues.php Lines 294 to 298 in 1a1c140 Same as framework/src/Illuminate/Collections/Traits/EnumeratesValues.php Lines 455 to 462 in 1a1c140 Same framework/src/Illuminate/Collections/LazyCollection.php Lines 1149 to 1153 in bf9f8f7
framework/src/Illuminate/Collections/LazyCollection.php Lines 1173 to 1177 in bf9f8f7 And framework/src/Illuminate/Collections/LazyCollection.php Lines 215 to 218 in bf9f8f7 |
|
Would it be safer to just modify |
|
Hmm - I guess this looks OK. |
|
@taylorotwell I will add a new check, because I will send a new commit changing Also a new test will be added using a callable string. |
|
What's the difference from the $city = $cities->first(
fn ($city) => $city->state->available && ($city->state->id === $stateId)
); |
Added
callablesupport tooperatorForWhere.Currently only Collection methods
whereandwhereFirstare used withoutcallablesupport.Adding callable to
operatorForWhereallow complex usages as:or