File tree 2 files changed +16
-5
lines changed
2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,10 @@ public function handle()
19
19
}
20
20
21
21
$ model = new $ option ;
22
+ $ usesCachableTrait = collect (class_uses ($ model ))
23
+ ->contains ("GeneaLabs\LaravelModelCaching\Traits\Cachable " );
22
24
23
- if (! method_exists ( $ model , ' flushCache ' ) ) {
25
+ if (! $ usesCachableTrait ) {
24
26
$ this ->error ("' {$ option }' is not an instance of CachedModel. " );
25
27
$ this ->line ("Only CachedModel instances can be flushed. " );
26
28
Original file line number Diff line number Diff line change @@ -22,16 +22,25 @@ protected function cache(array $tags = [])
22
22
}
23
23
24
24
if (is_subclass_of ($ cache ->getStore (), TaggableStore::class)) {
25
- if (is_a ($ this , CachedModel::class)) {
26
- array_push ($ tags , str_slug (get_called_class ()));
27
- }
28
-
25
+ $ tags = $ this ->addTagsWhenCalledFromCachedBuilder ($ tags );
29
26
$ cache = $ cache ->tags ($ tags );
30
27
}
31
28
32
29
return $ cache ;
33
30
}
34
31
32
+ protected function addTagsWhenCalledFromCachedBuilder (array $ tags ) : array
33
+ {
34
+ $ usesCachableTrait = collect (class_uses ($ this ))
35
+ ->contains ("GeneaLabs\LaravelModelCaching\Traits\Cachable " );
36
+
37
+ if (! $ usesCachableTrait ) {
38
+ array_push ($ tags , str_slug (get_called_class ()));
39
+ }
40
+
41
+ return $ tags ;
42
+ }
43
+
35
44
public function disableCache ()
36
45
{
37
46
cache ()->forever (self ::$ isCachableKey , true );
You can’t perform that action at this time.
0 commit comments