dds ss
dds ss

Reputation: 49

Laravel 5.4 pluck

I have a problem with the laravel5.4 pluck function.

I need to obtain a list (to be used in a form::select) with a list of cities (cap_citta) and the corresponding zip codes (cap_cap) as keys.

In my code I have the following line:

$items = Cap::pluck('cap_citta', 'cap_cap');

The problem is that I obtain only a partial list.

If I write

$items = Cap::pluck('cap_citta');

instead everything goes right (but I'm missing the keys).

Upvotes: 0

Views: 3187

Answers (2)

Hedam
Hedam

Reputation: 2249

You are doing everything right with:

$items = Cap::pluck('cap_cap', 'cap_citta');

Are you sure all entries have a key - cap_citta ?

Upvotes: 4

Adam
Adam

Reputation: 1299

Maybe

$collection = Cap::all();
$items = $collection->pluck('cap_citta', 'cap_cap');

Have a nice one!

Upvotes: -1

Related Questions