Skip to content

Conversation

AJenbo
Copy link
Contributor

@AJenbo AJenbo commented Nov 7, 2024

Corrected the parameter type in the PHPDoc for Collection::diffKeys() and Collection::diffKeysUsing() from array<TKey, TValue> to array<TKey, mixed>, as these methods only operate on the keys of the given array, making the value type irrelevant.

This lets you do something like:

$animals = Animal::pluck('name', 'id'); $animalFood = Food::pluck('id', 'animal_id'); if ($animals->diffKeys($animalFood) as $id) { throw new Exception('Missing food for ' . $animals[$id]); }

Tools previously flagged this usage as illegal due to the differing value types (food.id as int vs. animal.name as string), despite only the keys being compared.

@taylorotwell taylorotwell merged commit 9c86dd9 into laravel:11.x Nov 7, 2024
33 checks passed
@AJenbo AJenbo deleted the diffkeys branch November 7, 2024 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants