How to KeyBy where multiple items have the same key
PHP Snippet 1:
$countriesById = collect($allCountries)->groupBy('id');
PHP Snippet 2:
$filtered = $allCountries->filter(function ($item) use ($id) {
return $item->id == $id;
});
$filtered->all();