app/Filters/BaseFilter.php
public function has($values)
    {
        $hases = explode(',', $values);
        $model = $this->builder->getModel();
        $hases = collect($hases)->filter(function ($has) use($model) {
            if (str_contains($has, '.')) return ($model->{explode('.', $has)[0]}() instanceof Relation);
            return ($model->{$has}() instanceof Relation);
        })->toArray();
        $validator = validator([ 'values' => $hases ], [ 'values' => 'array|min:1' ]);
        return $this->builder->when(!$validator->fails(), function (Builder $query) use($hases) {
            foreach ($hases as $has) {
                $query->has($has);
            }
        });
    }
public function has($values)
    {
        $hases = explode(',', $values);
        $model = $this->builder->getModel();
        $hases = collect($hases)->filter(function ($has) use($model) {
            if (str_contains($has, '.')) return ($model->{explode('.', $has)[0]}() instanceof Relation);
            return ($model->{$has}() instanceof Relation);
        })->toArray();
        $validator = validator([ 'values' => $hases ], [ 'values' => 'array|min:1' ]);
        return $this->builder->when(!$validator->fails(), function (Builder $query) use($hases) {
            foreach ($hases as $has) {
                $query->has($has);
            }
        });
    }
public function has ( $ values ) { $ hases = explode ( ',' , $ values ) ; $ model = $ this -> builder -> getModel ( ) ; $ hases = collect ( $ hases ) -> filter ( function ( $ has ) use ( $ model ) { if ( str_contains ( $ has , '.' ) ) return ( $ model -> { explode ( '.' , $ has ) [ 0 ] } ( ) instanceof Relation ) ; return ( $ model -> { $ has } ( ) instanceof Relation ) ; } ) -> toArray ( ) ; $ validator = validator ( [ 'values' => $ hases ] , [ 'values' => 'array|min:1' ] ) ; return $ this -> builder -> when ( ! $ validator -> fails ( ) , function ( Builder $ query ) use ( $ hases ) { foreach ( $ hases as $ has ) { $ query -> has ( $ has ) ; } } ) ; }
Get collection of resources by has relation
@param  string $values
@return \Illuminate\Database\Eloquent\Builder
Get collection of resources by has relation