src/Database/Queries/Roles.php
public function constrainWhereAssignedTo($query, $model, array $keys = null)
    {
        list($model, $keys) = Helpers::extractModelAndKeys($model, $keys);

        $query->whereExists(function ($query) use ($model, $keys) {
            $table  = $model->getTable();
            $key    = "{$table}.{$model->getKeyName()}";
            $pivot  = Models::table('assigned_roles');
            $roles  = Models::table('roles');
            $prefix = Models::prefix();

            $query->from($table)
                  ->join($pivot, $key, '=', $pivot.'.entity_id')
                  ->whereRaw("{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id")
                  ->where("{$pivot}.entity_type", $model->getMorphClass())
                  ->whereIn($key, $keys);

            Models::scope()->applyToModelQuery($query, $roles);
            Models::scope()->applyToRelationQuery($query, $pivot);
        });
    }
public function constrainWhereAssignedTo($query, $model, array $keys = null)
    {
        list($model, $keys) = Helpers::extractModelAndKeys($model, $keys);

        $query->whereExists(function ($query) use ($model, $keys) {
            $table  = $model->getTable();
            $key    = "{$table}.{$model->getKeyName()}";
            $pivot  = Models::table('assigned_roles');
            $roles  = Models::table('roles');
            $prefix = Models::prefix();

            $query->from($table)
                  ->join($pivot, $key, '=', $pivot.'.entity_id')
                  ->whereRaw("{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id")
                  ->where("{$pivot}.entity_type", $model->getMorphClass())
                  ->whereIn($key, $keys);

            Models::scope()->applyToModelQuery($query, $roles);
            Models::scope()->applyToRelationQuery($query, $pivot);
        });
    }
public function constrainWhereAssignedTo ( $ query , $ model , array $ keys = null ) { list ( $ model , $ keys ) = Helpers :: extractModelAndKeys ( $ model , $ keys ) ; $ query -> whereExists ( function ( $ query ) use ( $ model , $ keys ) { $ table = $ model -> getTable ( ) ; $ key = "{$table}.{$model->getKeyName()}" ; $ pivot = Models :: table ( 'assigned_roles' ) ; $ roles = Models :: table ( 'roles' ) ; $ prefix = Models :: prefix ( ) ; $ query -> from ( $ table ) -> join ( $ pivot , $ key , '=' , $ pivot . '.entity_id' ) -> whereRaw ( "{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id" ) -> where ( "{$pivot}.entity_type" , $ model -> getMorphClass ( ) ) -> whereIn ( $ key , $ keys ) ; Models :: scope ( ) -> applyToModelQuery ( $ query , $ roles ) ; Models :: scope ( ) -> applyToRelationQuery ( $ query , $ pivot ) ; } ) ; }
Constrain the given roles query to those that were assigned to the given authorities.

@param  \Illuminate\Database\Eloquent\Builder  $query
@param  string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection  $model
@param  array  $keys
@return void
Constrain the given roles query to those that were assigned to the given authorities .