app/Services/SearchService.php
private function paginateQuery(Builder $query, Closure $row_mapper, Closure $row_filter, int $offset, int $limit): Collection
    {
        $collection = new Collection();

        foreach ($query->cursor() as $row) {
            $record = $row_mapper($row);
            // If the object has a method "canShow()", then use it to filter for privacy.
            if ($row_filter($record)) {
                if ($offset > 0) {
                    $offset--;
                } else {
                    if ($limit > 0) {
                        $collection->push($record);
                    }

                    $limit--;

                    if ($limit === 0) {
                        break;
                    }
                }
            }
        }


        return $collection;
    }
private function paginateQuery(Builder $query, Closure $row_mapper, Closure $row_filter, int $offset, int $limit): Collection
    {
        $collection = new Collection();

        foreach ($query->cursor() as $row) {
            $record = $row_mapper($row);
            // If the object has a method "canShow()", then use it to filter for privacy.
            if ($row_filter($record)) {
                if ($offset > 0) {
                    $offset--;
                } else {
                    if ($limit > 0) {
                        $collection->push($record);
                    }

                    $limit--;

                    if ($limit === 0) {
                        break;
                    }
                }
            }
        }


        return $collection;
    }
private function paginateQuery ( Builder $ query , Closure $ row_mapper , Closure $ row_filter , int $ offset , int $ limit ) : Collection { $ collection = new Collection ( ) ; foreach ( $ query -> cursor ( ) as $ row ) { $ record = $ row_mapper ( $ row ) ; // If the object has a method "canShow()", then use it to filter for privacy. if ( $ row_filter ( $ record ) ) { if ( $ offset > 0 ) { $ offset -- ; } else { if ( $ limit > 0 ) { $ collection -> push ( $ record ) ; } $ limit -- ; if ( $ limit === 0 ) { break ; } } } } return $ collection ; }
Paginate a search query.

@param Builder $query      Searches the database for the desired records.
@param Closure $row_mapper Converts a row from the query into a record.
@param Closure $row_filter
@param int     $offset     Skip this many rows.
@param int     $limit      Take this many rows.

@return Collection
Paginate a search query .