Łachówka w 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'];
$collection = collect([
['product_id' => 'prod-100', 'name' => 'Desk'],
['product_id' => 'prod-200', 'name' => 'Chair'],
]);
$plucked = $collection->pluck('name');
$plucked->all();
// ['Desk', 'Chair']
$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'];