Skip to content

Commit e5d93cd

Browse files
committed
Add truncate support
1 parent 6cce090 commit e5d93cd

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Traits/BuilderCaching.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ public function all($columns = ['*']) : Collection
1212

1313
return $this->model->get($columns);
1414
}
15+
16+
public function truncate()
17+
{
18+
if ($this->isCachable()) {
19+
$this->model->flushCache();
20+
}
21+
22+
return parent::truncate();
23+
}
1524
}

tests/Integration/Traits/BuilderCachingTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ public function testDisablingAllQuery()
2424
$this->assertInstanceOf(Collection::class, $allAuthors);
2525
$this->assertNull($cachedAuthors);
2626
}
27+
28+
public function testUsingTruncateInvalidatesCache()
29+
{
30+
(new Author)->get();
31+
Author::truncate();
32+
33+
$this->assertTrue((new Author)->get()->isEmpty());
34+
}
2735
}

0 commit comments

Comments
 (0)