You can do that with the keyBy function: https://laravel.com/docs/8.x/collections#method-keyby
$cars = [
['Item' => "Volvo", 'Price' => 22, 'NewPrice' => 18],
['Item' => "Volvo", 'Price' => 22, 'NewPrice' => 18.56],
['Item' => "BMW", 'Price' => 23, 'NewPrice' => 5.09],
['Item' => "Saab", 'Price' => 90, 'NewPrice' => 23],
['Item' => "Saab", 'Price' => 90, 'NewPrice' => 24.90],
['Item' => "Saab", 'Price' => 90, 'NewPrice' => 13.33],
];
$collection = new \Illuminate\Support\Collection($cars);
$cars = $collection->keyBy('Item');
// Or if you don't want the Item as key of the result.
$cars = $collection->keyBy('Item')->values();
claw-hammer liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community