“Laravel Array_pluck” Código de respuesta

Matriz de desplume en Laravel

$users = User::all()->pluck('field_name');
//for keys instead of [User::all()->pluck('id');] use
$user_ids = User::all()->modelKeys();
Code Alchemy

Laravel Array_pluck

$array = [
    ['developer' => ['id' => 1, 'name' => 'Taylor']],
    ['developer' => ['id' => 2, 'name' => 'Abigail']],
];

$array = array_pluck($array, 'developer.name');

// ['Taylor', 'Abigail'];
Lovely Loris

Laravel Collection Rock

$collection = collect([
    ['product_id' => 'prod-100', 'name' => 'Desk'],
    ['product_id' => 'prod-200', 'name' => 'Chair'],
]);

$plucked = $collection->pluck('name');

$plucked->all();

// ['Desk', 'Chair']
Agreeable Anaconda

arrancar laravado

$name = DB::table('users')->where('name', 'John')->pluck('name');
Lokesh003

Ejemplo de Laravel.

DB::table('users')->where('id', 1)->pluck('name')->first();
Mohamad

Laravel Array_pluck

$array = array_pluck($array, 'developer.name', 'developer.id');

// [1 => 'Taylor', 2 => 'Abigail'];
Lovely Loris

Respuestas similares a “Laravel Array_pluck”

Preguntas similares a “Laravel Array_pluck”

Más respuestas relacionadas con “Laravel Array_pluck” en PHP

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código