Zucker Array in Laravel
$users = User::all()->pluck('field_name');
//for keys instead of [User::all()->pluck('id');] use
$user_ids = User::all()->modelKeys();
Code Alchemy
$users = User::all()->pluck('field_name');
//for keys instead of [User::all()->pluck('id');] use
$user_ids = User::all()->modelKeys();
$array = [
['developer' => ['id' => 1, 'name' => 'Taylor']],
['developer' => ['id' => 2, 'name' => 'Abigail']],
];
$array = array_pluck($array, 'developer.name');
// ['Taylor', 'Abigail'];
$name = DB::table('users')->where('name', 'John')->pluck('name');
DB::table('users')->where('id', 1)->pluck('name')->first();
$array = array_pluck($array, 'developer.name', 'developer.id');
// [1 => 'Taylor', 2 => 'Abigail'];
$collection = collect([
'serial' => 'UX301', 'type' => 'screen', 'year' => 2009,
]);
$intersect = $collection->intersectByKeys([
'reference' => 'UX404', 'type' => 'tab', 'year' => 2011,
]);
$intersect->all();
// ['type' => 'screen', 'year' => 2009]