Laravel 5.2 has pretty nice Helpers, I would like to use them to do following:
I have Eloquent Model Collection:
$lesson->users(); // returns Eloquent collection of 3 users
pluck()
function would be useful, but it can get just single parameter. However I want to get output with two parameters, id
and name
, like this:
[
1=>['id'=>10,'name'=>'Michael Dook'],
2=>['id'=>16,'name'=>'Henry Babcock'],
3=>['id'=>19,'name'=>'Joe Nedd']
]
Is there any elegant solution for this?
users()
method returns a collection. This solution would only work ifusers()
returns a relationship (query builder). – Wordsmith