@@ -28,29 +28,40 @@ public function make() : array
28
28
$ tags = collect ($ this ->eagerLoad )
29
29
->keys ()
30
30
->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 );
43
32
44
33
return $ this ->getCachePrefix ()
45
34
. str_slug (get_class ($ relation ->getQuery ()->getModel ()));
46
35
})
47
- ->prepend (
48
- $ this ->getCachePrefix ()
49
- . str_slug (get_class ($ this ->model ))
50
- )
36
+ ->prepend ($ this ->getTagName ())
51
37
->values ()
52
38
->toArray ();
53
39
54
40
return $ tags ;
55
41
}
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
+ }
56
67
}
0 commit comments