<?php
“Laravel array_pluck”
pluck array in laravel
$users = User::all()->pluck('field_name');
//for keys instead of [User::all()->pluck('id');] use
$user_ids = User::all()->modelKeys();
laravel array_pluck
$array = [
['developer' => ['id' => 1, 'name' => 'Taylor']],
['developer' => ['id' => 2, 'name' => 'Abigail']],
];
$array = array_pluck($array, 'developer.name');
// ['Taylor', 'Abigail'];
pluck laravel
$name = DB::table('users')->where('name', 'John')->pluck('name');
Laravel array_pluck
$array = array_pluck($array, 'developer.name', 'developer.id');
// [1 => 'Taylor', 2 => 'Abigail'];
Laravel pluck
$users = Users::pluck('name','email');
dd($users);
0 comments:
Post a Comment
Thanks