src/Engine/Traits/FromModelTraitPart/CollectionTrait.php
public function getFiltered($page, $numRows, $sortAttr, $sortOrder, $searchAttr, $searchValue, $richFilters = [])
    {
        $query = $this->prepareQuery();

        $query = $this->richFiltersOnQuery($query, $richFilters);

        if ($sortAttr && $sortOrder && $this->inScope($sortAttr)) {
            $scope = $this->getScope($sortAttr);
            $query = $query->orderBy($scope, $sortOrder);
        }

        if ($searchAttr && $searchValue && $this->inScope($searchAttr)) {
            $scope = $this->getScope($searchAttr);
            $query = $query->where($scope, 'like', '%' . $searchValue . '%');
        }

        $collection = $query->get();

        $collection = $this->addPermissions($collection);

        $collection = $this->formatCollection($collection);

        $collection = $collection->each(function ($model) {
            $model = $this->formatModel($model);
        });

        if ($sortAttr && $sortOrder && ! $this->inScope($sortAttr)) {
            $collection = $sortOrder == 'asc'
                ? $collection->sortBy($sortAttr)
                : $collection->sortByDesc($sortAttr);
        }

        $collection = $this->richFiltersOnCollection($collection, $richFilters);

        if ($searchAttr && $searchValue && ! $this->inScope($searchAttr)) {
            $collection = $collection->filter(function ($model) use ($searchAttr, $searchValue) {
                $value = (string) $model->$searchAttr;
                $value = strtolower($value);
                $search = strtolower($searchValue);
                return strpos($value, $search) !== false;
            });
        }

        if ($page && $numRows) {
            $toSkip = ($page - 1) * $numRows;
            $count = $collection->count();
            $collection = $collection->take(- ($count - $toSkip))->take($numRows);
        } else if ($numRows)
            $collection = $collection->take($numRows);

        return collect(array_values($collection->toArray()));
    }
public function getFiltered($page, $numRows, $sortAttr, $sortOrder, $searchAttr, $searchValue, $richFilters = [])
    {
        $query = $this->prepareQuery();

        $query = $this->richFiltersOnQuery($query, $richFilters);

        if ($sortAttr && $sortOrder && $this->inScope($sortAttr)) {
            $scope = $this->getScope($sortAttr);
            $query = $query->orderBy($scope, $sortOrder);
        }

        if ($searchAttr && $searchValue && $this->inScope($searchAttr)) {
            $scope = $this->getScope($searchAttr);
            $query = $query->where($scope, 'like', '%' . $searchValue . '%');
        }

        $collection = $query->get();

        $collection = $this->addPermissions($collection);

        $collection = $this->formatCollection($collection);

        $collection = $collection->each(function ($model) {
            $model = $this->formatModel($model);
        });

        if ($sortAttr && $sortOrder && ! $this->inScope($sortAttr)) {
            $collection = $sortOrder == 'asc'
                ? $collection->sortBy($sortAttr)
                : $collection->sortByDesc($sortAttr);
        }

        $collection = $this->richFiltersOnCollection($collection, $richFilters);

        if ($searchAttr && $searchValue && ! $this->inScope($searchAttr)) {
            $collection = $collection->filter(function ($model) use ($searchAttr, $searchValue) {
                $value = (string) $model->$searchAttr;
                $value = strtolower($value);
                $search = strtolower($searchValue);
                return strpos($value, $search) !== false;
            });
        }

        if ($page && $numRows) {
            $toSkip = ($page - 1) * $numRows;
            $count = $collection->count();
            $collection = $collection->take(- ($count - $toSkip))->take($numRows);
        } else if ($numRows)
            $collection = $collection->take($numRows);

        return collect(array_values($collection->toArray()));
    }
public function getFiltered ( $ page , $ numRows , $ sortAttr , $ sortOrder , $ searchAttr , $ searchValue , $ richFilters = [ ] ) { $ query = $ this -> prepareQuery ( ) ; $ query = $ this -> richFiltersOnQuery ( $ query , $ richFilters ) ; if ( $ sortAttr && $ sortOrder && $ this -> inScope ( $ sortAttr ) ) { $ scope = $ this -> getScope ( $ sortAttr ) ; $ query = $ query -> orderBy ( $ scope , $ sortOrder ) ; } if ( $ searchAttr && $ searchValue && $ this -> inScope ( $ searchAttr ) ) { $ scope = $ this -> getScope ( $ searchAttr ) ; $ query = $ query -> where ( $ scope , 'like' , '%' . $ searchValue . '%' ) ; } $ collection = $ query -> get ( ) ; $ collection = $ this -> addPermissions ( $ collection ) ; $ collection = $ this -> formatCollection ( $ collection ) ; $ collection = $ collection -> each ( function ( $ model ) { $ model = $ this -> formatModel ( $ model ) ; } ) ; if ( $ sortAttr && $ sortOrder && ! $ this -> inScope ( $ sortAttr ) ) { $ collection = $ sortOrder == 'asc' ? $ collection -> sortBy ( $ sortAttr ) : $ collection -> sortByDesc ( $ sortAttr ) ; } $ collection = $ this -> richFiltersOnCollection ( $ collection , $ richFilters ) ; if ( $ searchAttr && $ searchValue && ! $ this -> inScope ( $ searchAttr ) ) { $ collection = $ collection -> filter ( function ( $ model ) use ( $ searchAttr , $ searchValue ) { $ value = ( string ) $ model -> $ searchAttr ; $ value = strtolower ( $ value ) ; $ search = strtolower ( $ searchValue ) ; return strpos ( $ value , $ search ) !== false ; } ) ; } if ( $ page && $ numRows ) { $ toSkip = ( $ page - 1 ) * $ numRows ; $ count = $ collection -> count ( ) ; $ collection = $ collection -> take ( - ( $ count - $ toSkip ) ) -> take ( $ numRows ) ; } else if ( $ numRows ) $ collection = $ collection -> take ( $ numRows ) ; return collect ( array_values ( $ collection -> toArray ( ) ) ) ; }
Get filtered collection
@param  integer $page
@param  integer $numRows
@param  string  $sortAttr
@param  string  $sortOrder
@param  string  $searchAttr
@param  string  $searchValue
@return Collection
Get filtered collection