在voyager中隐藏小部件 [英] Hide of widgets in voyager

查看:61
本文介绍了在voyager中隐藏小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Voyager在laravel 5.6中工作,我想实现旅行者的小部件,但是它向我展示了我创建的所有小部件,但是我需要向普通用户隐藏一些小部件,因为某些小部件只能由Admin访问.我无法隐藏显示所有小部件的小部件.预先感谢.

I'm working in laravel 5.6 with Voyager and I want to implement the widgets of the voyager but however it's showing me all the widgets I have Created but I need to hide some widgets from normal users as some widgets only accessible by Admin.I'm not able to hide the widgets it showing all widgets.. Thanks in advance.

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'),
    ]));
}

推荐答案

您需要更改窗口小部件的 shouldBeDisplayed 方法,如下所示:

you need to change widget's shouldBeDisplayed method as following:

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

它只是检查当前用户的角色是否为admin.

it simply checks wether current user's role is admin or not.

祝你好运

这篇关于在voyager中隐藏小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆