【问题标题】:Hide of widgets in voyager在 voyager 中隐藏小部件
【发布时间】:2019-06-11 06:24:36
【问题描述】:

我正在使用 Voyager 在 laravel 5.6 中工作,我想实现 voyager 的小部件,但是它向我显示了我创建的所有小部件,但我需要对普通用户隐藏一些小部件,因为某些小部件只能由管理员访问.我无法隐藏它显示所有小部件的小部件.. 提前致谢。

public function run()
{

     $count = \App\Organization::count();


    $string = trans_choice('Organization', $count);


    return view('voyager::dimmer', array_merge($this->config, [
        'icon' => 'voyager-edit',
        'title' => [
            'text' => "{$string} {$count}",
            'link' => route('org_data'),
        ],
        // 'image' => voyager_asset('images/widget-backgrounds/03.jpg'),
    ]));
}

【问题讨论】:

    标签: laravel voyager


    【解决方案1】:

    您需要更改小部件的shouldBeDisplayed 方法如下:

    public function shouldBeDisplayed(){
       return auth()->user()->hasRole('admin');
    }
    

    它只是检查当前用户的角色是否是管理员。

    祝你好运

    【讨论】: