Laravel 5 Eloquent with MongoDB - get array of column names from document -
this becoming frustrating beyond imagination.
i need column names table using eloquent orm in laravel 5 combined mongodb. have found examples, none of them working me made sql specifically. tried this , this without success, idea?
thanks!
it best use raw()
method in case , use native mongocollection methods find()
iterate on collection , keys in documents array:
// returns array of field names collection of user models. $keys = db::collection('users')->raw(function($collection) { $cursor = $collection->find(); $array = iterator_to_array($cursor); $fields = array(); foreach ($array $k=>$v) { foreach ($v $a=>$b) { $fields[] = $a; } } return array_values(array_unique($fields)); });
Comments
Post a Comment