Tuesday, March 7, 2017

Laravel collection manipulation

I have User model that has 2 fields: email and id
I have this query:

$users = User::all()->get();

the result will be 3 User objects in a Collection
I want to see the result as the following:

[87 => 'user@gmail.com', 92 => 'admin@gmail.com', 10 => 'super@gmail.com']

id will be the key and email will be the value.
Is that possible via Collection class to implement? thanks



via Shazam

Advertisement