Skip to content

Commit

Permalink
Added Spatie permission traits and fixed menu item edit dropdown issue
Browse files Browse the repository at this point in the history
  • Loading branch information
balajidharma committed Jan 20, 2024
1 parent 5389d30 commit 9fb4668
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Models/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace BalajiDharma\LaravelMenu\Models;

use BalajiDharma\LaravelMenu\Traits\MenuTree;
use BalajiDharma\LaravelMenu\Traits\spatiePermission;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class MenuItem extends Model
{
use spatiePermission;
use MenuTree {
MenuTree::boot as treeBoot;
}
Expand Down
1 change: 0 additions & 1 deletion src/Traits/MenuTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ public function allNodes($menuId, $ignoreItemId = null, $includeDisabledItems =
->when(! $includeDisabledItems, function ($query) {
$query->where('enabled', true);
})
->where('id', '!=', $ignoreItemId)
->orderBy($this->getOrderColumn())->get()->toArray();
}

Expand Down
18 changes: 18 additions & 0 deletions src/Traits/spatiePermission.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace BalajiDharma\LaravelMenu\Traits;

if (class_exists(\Spatie\Permission\PermissionRegistrar::class)) {
trait spatiePermission
{
use \Spatie\Permission\Traits\HasRoles, \Spatie\Permission\Traits\HasPermissions;
public $hasSpatiePermission = true;

protected $guard_name = 'web';
}
} else {
trait spatiePermission
{
public $hasSpatiePermission = false;
}
}

0 comments on commit 9fb4668

Please sign in to comment.