3
3
namespace ctf0 \SimpleMenu \Models ;
4
4
5
5
use Baum \Node ;
6
- use Illuminate \Support \Facades \File ;
7
6
use Illuminate \Support \Facades \Cache ;
8
7
use Spatie \Permission \Traits \HasRoles ;
9
8
use Spatie \Translatable \HasTranslations ;
10
9
use Mcamara \LaravelLocalization \Facades \LaravelLocalization ;
11
10
12
11
class Page extends Node
13
12
{
14
- use HasRoles, HasTranslations, ClearCacheTrait ;
13
+ use HasRoles, HasTranslations;
15
14
16
15
protected $ with = ['roles ' , 'permissions ' , 'menus ' ];
17
16
protected $ appends = ['nests ' ];
18
- public $ translatable = ['title ' , 'body ' , 'desc ' , 'prefix ' , 'url ' ];
19
17
protected $ guard_name = 'web ' ;
20
18
protected $ hidden = [
21
19
'children ' , 'roles ' , 'permissions ' ,
22
20
'menus ' , 'pivot ' , 'parent_id ' ,
23
21
'lft ' , 'rgt ' , 'depth ' ,
24
22
];
25
-
26
- // protected static function boot()
27
- // {
28
- // parent::boot();
29
- // static::addGlobalScope('url', function (Illuminate\Database\Eloquent\Builder $builder) {
30
- // $builder->where('url->' . LaravelLocalization::getCurrentLocale(), '!=', '');
31
- // });
32
- // }
23
+ public $ translatable = ['title ' , 'body ' , 'desc ' , 'prefix ' , 'url ' ];
33
24
34
25
public function menus ()
35
26
{
@@ -66,12 +57,14 @@ public function getAttributeValue($key)
66
57
*/
67
58
public function assignToMenus ($ menus )
68
59
{
69
- return $ this ->menus ()->attach ($ menus );
60
+ $ this ->menus ()->attach ($ menus );
61
+ $ this ->touch ();
70
62
}
71
63
72
64
public function syncMenus ($ menus )
73
65
{
74
- return $ this ->menus ()->sync ($ menus );
66
+ $ this ->menus ()->sync ($ menus );
67
+ $ this ->touch ();
75
68
}
76
69
77
70
/**
@@ -91,12 +84,15 @@ public function getAncestors($columns = ['*'])
91
84
public function getNestsAttribute ()
92
85
{
93
86
return Cache::rememberForever ($ this ->getCrntLocale () . "- {$ this ->route_name }_nests " , function () {
94
- $ childs = array_flatten (current ($ this ->getDescendants ()->toHierarchy ()));
95
-
96
- return count ($ childs ) ? $ childs : null ;
87
+ return $ childs = array_flatten (current ($ this ->getDescendants ()->toHierarchy ()));
97
88
});
98
89
}
99
90
91
+ /**
92
+ * clear Nesting.
93
+ *
94
+ * @return [type] [description]
95
+ */
100
96
public function destroyDescendants ()
101
97
{
102
98
if (config ('simpleMenu.deletePageAndNests ' )) {
@@ -108,10 +104,7 @@ public function destroyDescendants()
108
104
109
105
public function clearSelfAndDescendants ()
110
106
{
111
- // self
112
107
$ this ->makeRoot ();
113
-
114
- // childs
115
108
$ this ->clearNests ();
116
109
}
117
110
@@ -131,32 +124,6 @@ protected function clearNests()
131
124
$ one ->makeRoot ();
132
125
});
133
126
134
- $ this ->cleanData ();
135
- }
136
-
137
- /**
138
- * clear cacheing and stuff.
139
- *
140
- * @param [type] $page [description]
141
- *
142
- * @return [type] [description]
143
- */
144
- public function cleanData ()
145
- {
146
- $ route_name = $ this ->route_name ;
147
-
148
- // clear page session
149
- session ()->forget ($ route_name );
150
-
151
- // remove the route file
152
- File::delete (config ('simpleMenu.routeListPath ' ));
153
-
154
- // clear page cache
155
- $ this ->clearCache ($ route_name );
156
- $ this ->clearCache ('_ancestors ' );
157
- $ this ->clearCache ('_nests ' );
158
-
159
- // clear menu cache
160
- $ this ->clearCache ('Menu ' );
127
+ $ this ->touch ();
161
128
}
162
129
}
0 commit comments