-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[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
callable
support tooperatorForWhere
.Currently only Collection methods
where
andwhereFirst
are used withoutcallable
support.Adding callable to
operatorForWhere
allow complex usages as:or