“Laravel Collection Puck” Réponses codées

Traiter le tableau à 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 Puck

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

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

$plucked->all();

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

cueillir Laravel

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

Laravel Pluck Exemple

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

Réponses similaires à “Laravel Collection Puck”

Questions similaires à “Laravel Collection Puck”

Plus de réponses similaires à “Laravel Collection Puck” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code