1

我正在使用背包在我的项目中创建管理面板。我有两种类型的用户,一种是超级管理员,第二种是管理员。我只是想授予超级管理员权限,因为他可以列出、添加、编辑数据库中的所有行。

但管理员只能编辑、删除和列出他自己创建的那些行..

所以请帮助我,我是 laravel 背包的新手??

4

1 回答 1

1

过滤您在setup()实体 CrudController 的方法中显示的结果,然后禁止访问更新/销毁方法。

您的结果可能如下所示:

public function setup() 
{
    // take care of LIST operations
    if (\Auth::user()->hasRole('admin')) {
       $this->crud->addClause('where', 'author_id', '=', \Auth::user()->id);
    }
}

update()此外,您需要在您的和方法中放置检查destroy(),以不允许管理员删除其他人的条目。

// place this both inside your update() and inside your destroy() method 
if (\Auth::user()->hasRole('admin') && $this->crud->entry->author_id!=\Auth::user()->id) {
   abort(405);
}

希望能帮助到你。

于 2017-04-20T15:20:58.343 回答