Recently, I learned (or re-learned) that the pluck()
method on a Laravel Collection accepts a second parameter to specify how you'd like the Collection keyed. Super handy in certain cases!
<?php
$posts = collect([
['slug' => 'post-1', 'title' => 'Taylor is cool'],
['slug' => 'post-2', 'title' => 'Tyler is the real MVP'],
]);
$plucked = $posts->pluck('title', 'slug');
// ['post-1' => 'Taylor is cool', 'post-2' => 'Tyler is the real MVP']