Skip to content

Commit d182c12

Browse files
committed
WIP
1 parent 8c1ec1c commit d182c12

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/CacheTags.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,40 @@ public function make() : array
2828
$tags = collect($this->eagerLoad)
2929
->keys()
3030
->map(function ($relationName) {
31-
$relation = collect(explode('.', $relationName))
32-
->reduce(function ($carry, $name) {
33-
if (! $carry) {
34-
$carry = $this->model;
35-
}
36-
37-
if ($carry instanceof Relation) {
38-
$carry = $carry->getQuery()->getModel();
39-
}
40-
41-
return $carry->{$name}();
42-
});
31+
$relation = $this->getRelation($relationName);
4332

4433
return $this->getCachePrefix()
4534
. str_slug(get_class($relation->getQuery()->getModel()));
4635
})
47-
->prepend(
48-
$this->getCachePrefix()
49-
. str_slug(get_class($this->model))
50-
)
36+
->prepend($this->getTagName())
5137
->values()
5238
->toArray();
5339

5440
return $tags;
5541
}
42+
43+
protected function getRelatedModel($carry) : Model
44+
{
45+
if ($carry instanceof Relation) {
46+
return $carry->getQuery()->getModel();
47+
}
48+
49+
return $carry;
50+
}
51+
52+
protected function getRelation(string $relationName) : Relation
53+
{
54+
return collect(explode('.', $relationName))
55+
->reduce(function ($carry, $name) {
56+
$carry = $carry ?: $this->model;
57+
$carry = $this->getRelatedModel($carry);
58+
59+
return $carry->{$name}();
60+
});
61+
}
62+
63+
protected function getTagName() : string
64+
{
65+
return $this->getCachePrefix() . str_slug(get_class($this->model));
66+
}
5667
}

0 commit comments

Comments
 (0)