Silber\Bouncer\Database\Queries\Abilities::getAuthorityRoleConstraint PHP Method

getAuthorityRoleConstraint() protected method

Get a constraint for roles that are assigned to the given authority.
protected getAuthorityRoleConstraint ( Model $authority ) : Closure
$authority Illuminate\Database\Eloquent\Model
return Closure
    protected 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 . '.id', $authority->getKey());
        };
    }