takielias / tablar

Tablar: A Laravel Dashboard Preset Based on Tabler HTML Template + Vite. https://tablar.ebuz.xyz/docs
https://tablar.ebuz.xyz
MIT License
272 stars 33 forks source link

tabler laratrust #29

Closed haithamrdina closed 8 months ago

haithamrdina commented 8 months ago

I followed the same instructions in the documentation for permissions using laratrust but it doesn't work.

i have 2 roles super_admin , manager and i have follow all steps but nothing change in menu

takielias commented 8 months ago

@haithamrdina Could you please try this?

<?php

namespace App\Filter;

use Illuminate\Support\Facades\Auth;
use TakiElias\Tablar\Menu\Filters\FilterInterface;

class RolePermissionMenuFilter implements FilterInterface
{
    public function transform($item)
    {
        return $this->isVisible($item) ? $item['header'] ?? $item : false;
    }

    protected function isVisible($item)
    {
        $user = Auth::user();

        if (isset($item['hasAnyRole']) && !$user->hasRole($item['hasAnyRole'], null, true)) {
            return false;
        }

        if (isset($item['hasRole']) && !$user->hasRole($item['hasRole'])) {
            return false;
        }

        if (isset($item['hasAnyPermission']) && !$user->isAbleTo($item['hasAnyPermission'])) {
            return false;
        }

        return true;
    }
}
haithamrdina commented 8 months ago

thank you so much @takielias