Skip to content

Commit d8bd679

Browse files
committed
Fix the call to makeCacheKey from the previous commit and add sane defaults to makeCacheKey
1 parent dbdaca5 commit d8bd679

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/CachedModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function all($columns = ['*'])
5555
$class = get_called_class();
5656
$instance = new $class;
5757
$tags = [str_slug(get_called_class())];
58-
$key = makeCacheKey();
58+
$key = $instance->makeCacheKey();
5959

6060
return $instance->cache($tags)
6161
->rememberForever($key, function () use ($columns) {

src/Traits/Cachable.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use GeneaLabs\LaravelModelCaching\CacheTags;
55
use GeneaLabs\LaravelModelCaching\CachedModel;
66
use Illuminate\Cache\TaggableStore;
7+
use Illuminate\Database\Query\Builder;
78

89
trait Cachable
910
{
@@ -46,7 +47,11 @@ protected function makeCacheKey(
4647
$idColumn = null,
4748
string $keyDifferentiator = ''
4849
) : string {
49-
return (new CacheKey($this->eagerLoad, $this->model, $this->query))
50+
$eagerLoad = $this->eagerLoad ?? [];
51+
$model = $this->model ?? $this;
52+
$query = $this->query ?? app(Builder::class);
53+
54+
return (new CacheKey($eagerLoad, $model, $query))
5055
->make($columns, $idColumn, $keyDifferentiator);
5156
}
5257

0 commit comments

Comments
 (0)