File tree Expand file tree Collapse file tree 3 files changed +17
-23
lines changed
Expand file tree Collapse file tree 3 files changed +17
-23
lines changed Original file line number Diff line number Diff line change 22
33namespace BalajiDharma \LaravelMenu \Models ;
44
5+ use BalajiDharma \LaravelMenu \Traits \LaravelCategories ;
56use BalajiDharma \LaravelMenu \Traits \MenuTree ;
67use BalajiDharma \LaravelMenu \Traits \SpatiePermission ;
78use Illuminate \Database \Eloquent \Model ;
89use Illuminate \Database \Eloquent \Relations \BelongsTo ;
910
1011class MenuItem extends Model
1112{
12- use MenuTree {
13- MenuTree::boot as treeBoot;
14- }
15- use SpatiePermission;
13+ use LaravelCategories, MenuTree, SpatiePermission;
1614
1715 /**
1816 * The attributes that aren't mass assignable.
Original file line number Diff line number Diff line change 22
33namespace BalajiDharma \LaravelMenu \Traits ;
44
5- if (class_exists (\Spatie \ Permission \PermissionRegistrar ::class)) {
5+ if (class_exists (\BalajiDharma \ LaravelCategory \CategoryServiceProvider ::class)) {
66 trait LaravelCategories
77 {
88 use \BalajiDharma \LaravelCategory \Traits \HasCategories;
Original file line number Diff line number Diff line change @@ -13,6 +13,20 @@ trait MenuTree
1313 */
1414 protected $ queryCallback ;
1515
16+ /**
17+ * {@inheritdoc}
18+ */
19+ protected static function bootMenuTree ()
20+ {
21+ static ::saving (function (Model $ branch ) {
22+ $ parentColumn = $ branch ->getParentColumn ();
23+
24+ if (Request::filled ($ parentColumn ) && Request::input ($ parentColumn ) == $ branch ->getKey ()) {
25+ throw InvalidParent::create ();
26+ }
27+ });
28+ }
29+
1630 /**
1731 * Get children of current node.
1832 *
@@ -334,24 +348,6 @@ public function initializeMenuTree()
334348 $ this ->appends = array_unique (array_merge ($ this ->appends , ['link ' ]));
335349 }
336350
337- /**
338- * {@inheritdoc}
339- */
340- protected static function boot ()
341- {
342- parent ::boot ();
343-
344- static ::saving (function (Model $ branch ) {
345- $ parentColumn = $ branch ->getParentColumn ();
346-
347- if (Request::filled ($ parentColumn ) && Request::input ($ parentColumn ) == $ branch ->getKey ()) {
348- throw InvalidParent::create ();
349- }
350-
351- return $ branch ;
352- });
353- }
354-
355351 protected function checkHasPermission ($ menuItem )
356352 {
357353 if (! $ this ->hasSpatiePermission ) {
You can’t perform that action at this time.
0 commit comments