Reputation: 21
ModalName::pluck('id')->toArray();
i want id to be associative array with certain defined key. such as 'my_key'=>id in a pluck
Upvotes: 0
Views: 956
Reputation: 3972
First of all pluck() return you already an array so no need to call toArray().
Yes you can make it associative by passing another argument on pluck method. Like this
$plucked = $collection->pluck('name', 'product_id');
sample result
['prod-100' => 'Desk', 'prod-200' => 'Chair']
please see docs here source
so in your case
ModalName::all()->pluck('id', 'name'); // name = field in your table
Upvotes: 1