/** * * @return Model */ public function getModelWithRelations() { $model = $this->getModel(); foreach ($this->modelBuilder->getRelations() as $alias => $relation) { if ($relation->getType() == 'belongsToMany') { $model = $model->with($alias); } } return $model; }