Skip to content

Commit

Permalink
Updated paginator with comments from fadion#3
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Wright committed Jul 27, 2015
1 parent fe213ac commit 5e9b993
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "alexanderwright/bouncy",
"name": "fadion/bouncy",
"description": "Map Elasticsearch results to Eloquent models",
"license": "MIT",
"keywords": ["laravel", "elasticsearch", "eloquent"],
Expand Down
12 changes: 7 additions & 5 deletions src/Fadion/Bouncy/ElasticCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;

This comment has been minimized.

Copy link
@vikram0460

vikram0460 Jun 19, 2017

use Illuminate\Support\Facades\URL;


class ElasticCollection extends Collection {

Expand All @@ -28,12 +30,12 @@ public function __construct($response, $instance)
*/
public function paginate($perPage = 15)
{
$paginator = new Paginator($this->items, $perPage);

$start = ($paginator->currentPage() - 1) * $perPage;
$sliced = array_slice($this->items, $start, $perPage);
$page = Paginator::resolveCurrentPage() ?: 1;
$path = '/' . \Request::path();

This comment has been minimized.

Copy link
@vikram0460

vikram0460 Jun 19, 2017

$path = URL::to('/').'/'.\Request::path();

$sliced = array_slice($this->items, ($page - 1) * $perPage, $perPage);
$total = count($this->items);

return new Paginator($sliced, $perPage);
return new LengthAwarePaginator($sliced, $total, $perPage, $page, compact('path'));
}

/**
Expand Down

1 comment on commit 5e9b993

@vikram0460
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AlexanderWright with your solution pagination is working. But it is working only for absolute path. It is not working for relative. I have added two comments to fix this issue.
@fadion Thanks a lot for the plug-in, it is great. Kindly accept merge request from @AlexanderWright which resolves pagination issue in the Laravel 5.4.

Please sign in to comment.