src/Database/Queries/Abilities.php
protected static function getAuthorityRoleConstraint(Model $authority)
    {
        return function ($query) use ($authority) {
            $pivot  = Models::table('assigned_roles');
            $roles  = Models::table('roles');
            $table  = $authority->getTable();
            $prefix = Models::prefix();

            $query->from($table)
                  ->join($pivot, "{$table}.{$authority->getKeyName()}", '=', $pivot.'.entity_id')
                  ->whereRaw("{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id")
                  ->where($pivot.'.entity_type', $authority->getMorphClass())
                  ->where("{$table}.{$authority->getKeyName()}", $authority->getKey());

            Models::scope()->applyToModelQuery($query, $roles);
            Models::scope()->applyToRelationQuery($query, $pivot);
        };
    }
protected static function getAuthorityRoleConstraint(Model $authority)
    {
        return function ($query) use ($authority) {
            $pivot  = Models::table('assigned_roles');
            $roles  = Models::table('roles');
            $table  = $authority->getTable();
            $prefix = Models::prefix();

            $query->from($table)
                  ->join($pivot, "{$table}.{$authority->getKeyName()}", '=', $pivot.'.entity_id')
                  ->whereRaw("{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id")
                  ->where($pivot.'.entity_type', $authority->getMorphClass())
                  ->where("{$table}.{$authority->getKeyName()}", $authority->getKey());

            Models::scope()->applyToModelQuery($query, $roles);
            Models::scope()->applyToRelationQuery($query, $pivot);
        };
    }
protected static function getAuthorityRoleConstraint ( Model $ authority ) { return function ( $ query ) use ( $ authority ) { $ pivot = Models :: table ( 'assigned_roles' ) ; $ roles = Models :: table ( 'roles' ) ; $ table = $ authority -> getTable ( ) ; $ prefix = Models :: prefix ( ) ; $ query -> from ( $ table ) -> join ( $ pivot , "{$table}.{$authority->getKeyName()}" , '=' , $ pivot . '.entity_id' ) -> whereRaw ( "{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id" ) -> where ( $ pivot . '.entity_type' , $ authority -> getMorphClass ( ) ) -> where ( "{$table}.{$authority->getKeyName()}" , $ authority -> getKey ( ) ) ; Models :: scope ( ) -> applyToModelQuery ( $ query , $ roles ) ; Models :: scope ( ) -> applyToRelationQuery ( $ query , $ pivot ) ; } ; }
Get a constraint for roles that are assigned to the given authority.

@param  \Illuminate\Database\Eloquent\Model  $authority
@return \Closure
Get a constraint for roles that are assigned to the given authority .