protected static function getEveryoneConstraint($allowed)
    {
        return function ($query) use ($allowed) {
            $permissions = Models::table('permissions');
            $abilities   = Models::table('abilities');
            $prefix      = Models::prefix();

            $query->from($permissions)
                  ->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id")
                  ->where("{$permissions}.forbidden", ! $allowed)
                  ->whereNull('entity_id');

            Models::scope()->applyToRelationQuery($query, $permissions);
        };
    }