【问题标题】:October CMS: How to extend the backend user with role scope十月 CMS:如何扩展具有角色范围的后端用户
【发布时间】:2017-04-09 09:31:06
【问题描述】:

我已经能够扩展 Backend\Models\User 类并添加一个作用域查询方法来仅检索超级用户:

public function boot()
{
    User::extend(function($model) {
        $model->addDynamicMethod('scopeIsSuperUser', function($query) {
            return $query->where('is_superuser', 1);
        });
    });
}

如何为特定组中的用户设置范围方法?就像我只想要角色为“BookManager”的用户。是否可以使用已经在Backend\Models\User 类上定义的$groups 关系?

public $belongsToMany = [
    'groups' => ['Backend\Models\UserGroup', 'table' => 'backend_users_groups']
];

【问题讨论】:

    标签: php content-management-system backend octobercms


    【解决方案1】:

    应该这样做

    User::extend(function($model) {
        $model->addDynamicMethod('scopeIsBookManager', function($query) {
            return $query->whereHas('groups', function ($query) {
                $query->where('code', 'BookManager');
            });
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2019-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-23
      相关资源
      最近更新 更多