diff --git a/src/app/Library/CrudPanel/Traits/Read.php b/src/app/Library/CrudPanel/Traits/Read.php index 9c9e050caf..3fb51336e9 100644 --- a/src/app/Library/CrudPanel/Traits/Read.php +++ b/src/app/Library/CrudPanel/Traits/Read.php @@ -2,6 +2,8 @@ namespace Backpack\CRUD\app\Library\CrudPanel\Traits; +use Exception; + /** * Properties and methods used by the List operation. */ @@ -82,8 +84,22 @@ public function autoEagerLoadRelationshipColumns() { $relationships = $this->getColumnsRelationships(); - if (count($relationships)) { - $this->with($relationships); + foreach ($relationships as $relation) { + if (strpos($relation, '.') !== false) { + $parts = explode('.', $relation); + $model = $this->model; + + // Iterate over each relation part to find the valid relations without attributes + // We should eager load the relation but not the attribute + foreach ($parts as $i => $part) { + try { + $model = $model->$part()->getRelated(); + } catch (Exception $e) { + $relation = join('.', array_slice($parts, 0, $i)); + } + } + } + $this->with($relation); } }