with('translations') ->orderBy('id', 'asc'); $total = (clone $query)->count(); if ($offset > $total) { $offset = max(0, $total - $perPage); } $items = $query ->offset($offset) ->limit($perPage) ->get(); $currentPage = $total > 0 ? (int) floor($offset / $perPage) + 1 : 1; return new Paginator( new LengthAwarePaginator( $items, $total, $perPage, $currentPage, ['path' => request()->url()] ) ); } }