Skip to content

Commit 3835414

Browse files
committed
Added Laravel Category Trait
1 parent e8cdff4 commit 3835414

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

src/Models/MenuItem.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
namespace BalajiDharma\LaravelMenu\Models;
44

5+
use BalajiDharma\LaravelMenu\Traits\LaravelCategories;
56
use BalajiDharma\LaravelMenu\Traits\MenuTree;
67
use BalajiDharma\LaravelMenu\Traits\SpatiePermission;
78
use Illuminate\Database\Eloquent\Model;
89
use Illuminate\Database\Eloquent\Relations\BelongsTo;
910

1011
class 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.

src/Traits/LaravelCategories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace 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;

src/Traits/MenuTree.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)