src/Traits/LaratrustHasScopes.php
public function scopeWherePermissionIs($query, $permission = '', $boolean = 'and')
    {
        $method = $boolean == 'and' ? 'where' : 'orWhere';

        return $query->$method(function ($query) use ($permission) {
            $query->whereHas('roles.permissions', function ($permissionQuery) use ($permission) {
                $permissionQuery->where('name', $permission);
            })->orWhereHas('permissions', function ($permissionQuery) use ($permission) {
                $permissionQuery->where('name', $permission);
            });
        });
    }
public function scopeWherePermissionIs($query, $permission = '', $boolean = 'and')
    {
        $method = $boolean == 'and' ? 'where' : 'orWhere';

        return $query->$method(function ($query) use ($permission) {
            $query->whereHas('roles.permissions', function ($permissionQuery) use ($permission) {
                $permissionQuery->where('name', $permission);
            })->orWhereHas('permissions', function ($permissionQuery) use ($permission) {
                $permissionQuery->where('name', $permission);
            });
        });
    }
public function scopeWherePermissionIs ( $ query , $ permission = '' , $ boolean = 'and' ) { $ method = $ boolean == 'and' ? 'where' : 'orWhere' ; return $ query -> $ method ( function ( $ query ) use ( $ permission ) { $ query -> whereHas ( 'roles.permissions' , function ( $ permissionQuery ) use ( $ permission ) { $ permissionQuery -> where ( 'name' , $ permission ) ; } ) -> orWhereHas ( 'permissions' , function ( $ permissionQuery ) use ( $ permission ) { $ permissionQuery -> where ( 'name' , $ permission ) ; } ) ; } ) ; }
This scope allows to retrieve the users with a specific permission.
@param  \Illuminate\Database\Eloquent\Builder  $query
@param  string  $permission
@return \Illuminate\Database\Eloquent\Builder
This scope allows to retrieve the users with a specific permission .