src/Database/Queries/Abilities.php
protected static function getAuthorityConstraint(Model $authority, $allowed)
    {
        return function ($query) use ($authority, $allowed) {
            $permissions = Models::table('permissions');
            $abilities   = Models::table('abilities');
            $table       = $authority->getTable();
            $prefix      = Models::prefix();

            $query->from($table)
                  ->join($permissions, "{$table}.{$authority->getKeyName()}", '=', $permissions.'.entity_id')
                  ->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id")
                  ->where("{$permissions}.forbidden", ! $allowed)
                  ->where("{$permissions}.entity_type", $authority->getMorphClass())
                  ->where("{$table}.{$authority->getKeyName()}", $authority->getKey());

            Models::scope()->applyToModelQuery($query, $abilities);
            Models::scope()->applyToRelationQuery($query, $permissions);
        };
    }
protected static function getAuthorityConstraint(Model $authority, $allowed)
    {
        return function ($query) use ($authority, $allowed) {
            $permissions = Models::table('permissions');
            $abilities   = Models::table('abilities');
            $table       = $authority->getTable();
            $prefix      = Models::prefix();

            $query->from($table)
                  ->join($permissions, "{$table}.{$authority->getKeyName()}", '=', $permissions.'.entity_id')
                  ->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id")
                  ->where("{$permissions}.forbidden", ! $allowed)
                  ->where("{$permissions}.entity_type", $authority->getMorphClass())
                  ->where("{$table}.{$authority->getKeyName()}", $authority->getKey());

            Models::scope()->applyToModelQuery($query, $abilities);
            Models::scope()->applyToRelationQuery($query, $permissions);
        };
    }
protected static function getAuthorityConstraint ( Model $ authority , $ allowed ) { return function ( $ query ) use ( $ authority , $ allowed ) { $ permissions = Models :: table ( 'permissions' ) ; $ abilities = Models :: table ( 'abilities' ) ; $ table = $ authority -> getTable ( ) ; $ prefix = Models :: prefix ( ) ; $ query -> from ( $ table ) -> join ( $ permissions , "{$table}.{$authority->getKeyName()}" , '=' , $ permissions . '.entity_id' ) -> whereRaw ( "{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id" ) -> where ( "{$permissions}.forbidden" , ! $ allowed ) -> where ( "{$permissions}.entity_type" , $ authority -> getMorphClass ( ) ) -> where ( "{$table}.{$authority->getKeyName()}" , $ authority -> getKey ( ) ) ; Models :: scope ( ) -> applyToModelQuery ( $ query , $ abilities ) ; Models :: scope ( ) -> applyToRelationQuery ( $ query , $ permissions ) ; } ; }
Get a constraint for abilities that have been granted to the given authority.

@param  \Illuminate\Database\Eloquent\Model  $authority
@param  bool  $allowed
@return \Closure
Get a constraint for abilities that have been granted to the given authority .