Skip to content

Commit 422cc68

Browse files
committed
Fix tag generation for nested relationships
1 parent 60ecca9 commit 422cc68

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/CachedBuilder.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function getQueryColumns(array $columns) : string
7373
protected function getWhereClauses() : string
7474
{
7575
return collect($this->query->wheres)->reduce(function ($carry, $where) {
76-
$value = $where['value'] ?? implode('_', $where['values']) ?? '';
76+
$value = $where['value'] ?? implode('_', ($where['values'] ?? []));
7777

7878
return "{$carry}-{$where['column']}_{$value}";
7979
}) ?: '';
@@ -93,13 +93,21 @@ protected function getWithModels() : string
9393
protected function getCacheTags() : array
9494
{
9595
return collect($this->eagerLoad)->keys()
96-
->map(function ($name) {
97-
return str_slug(get_class(
98-
$this->model
99-
->{$name}()
100-
->getQuery()
101-
->model
102-
));
96+
->map(function ($relationName) {
97+
$relation = collect(explode('.', $relationName))
98+
->reduce(function ($carry, $name) use ($relationName) {
99+
if (! $carry) {
100+
$carry = $this->model;
101+
}
102+
103+
if ($carry instanceof Relation) {
104+
$carry = $carry->getQuery()->model;
105+
}
106+
107+
return $carry->{$name}();
108+
});
109+
110+
return str_slug(get_class($relation->getQuery()->model));
103111
})
104112
->prepend(str_slug(get_class($this->model)))
105113
->values()

0 commit comments

Comments
 (0)