Best way to make an eloquent collection a custom array

What is the best way to make Object::all() to array('object_id', 'object_name') ? I need some good code to use the eloquent collection for SELECT: {{ Form:select('objects', $custom_array) }} . Is a for loop the only way to do this?

+7
source share
1 answer

I think you are looking for toArray() :

 User::all()->toArray(); 

http://four.laravel.com/docs/eloquent#converting-to-arrays-or-json

To get an array that can be used directly with Form::select() , you can use the following:

 $contacts = Contact::orderBy('name')->lists('name', 'id'); $contacts = count($contacts) > 0 ? $contacts : array(); {{ Form::select('contact', $contacts) }} 
+16
source

All Articles