Laravel flatten and pluck from multidimensional collection
问题 I have to retrieve just an array of id from the given collection, something like [10,54,61,21,etc] . I've tried flatten , pluck , but nothing seems to work apart from a foreach which is something I would like to remove at this step. // Model class Children extends Eloquent { public function directChildrens(){ return $this->hasMany('App\Children','father_id','id')->select('id','father_id'); } public function childrens(){ return $this->directChildrens()->with('childrens'); } } // Controller