Skip to content

Commit a80d018

Browse files
authored
Ignore Pivot models
1 parent fb8166c commit a80d018

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/TagFinder.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Anorgan\LaravelCache;
44

55
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\Pivot;
67
use Illuminate\Support\Collection;
78

89
/**
@@ -18,6 +19,12 @@ class TagFinder
1819
public function find($models)
1920
{
2021
if ($models instanceof Model) {
22+
23+
// Ignore Pivot models
24+
if ($models instanceof Pivot) {
25+
return [];
26+
}
27+
2128
$models = collect([$models]);
2229
}
2330

@@ -45,13 +52,21 @@ private function getTagsFromCollection(Collection $collection)
4552
*/
4653
private function getTags(Model $model)
4754
{
55+
if ($model instanceof Pivot) {
56+
// Ignore Pivot models
57+
return [];
58+
}
59+
4860
$tags = [
4961
$this->createTag($model),
5062
];
5163

5264
foreach ($model->getRelations() as $relation) {
5365
if ($relation instanceof Collection) {
5466
$tags = array_merge($tags, $this->getTagsFromCollection($relation));
67+
} elseif ($relation instanceof Pivot) {
68+
// Ignore Pivot models
69+
$tags = [];
5570
} elseif ($relation instanceof Model) {
5671
$tags = array_merge($tags, $this->getTags($relation));
5772
}

0 commit comments

Comments
 (0)