Skip to content

Commit

Permalink
Merge pull request #2094 from LuckyCyborg/4.0
Browse files Browse the repository at this point in the history
Improve the Shared\Pagination
  • Loading branch information
LuckyCyborg authored Jul 23, 2018
2 parents fbd7541 + ebdeade commit bbaf5fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/Platform/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Define The Application Version
//--------------------------------------------------------------------------

define('VERSION', '4.0.76');
define('VERSION', '4.0.77');

//--------------------------------------------------------------------------
// Set PHP Error Reporting Options
Expand Down
33 changes: 21 additions & 12 deletions shared/Pagination/Middleware/SetupRoutePagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,9 @@ public function handle(Request $request, Closure $next)

Paginator::currentPathResolver(function ($pageName = 'page') use ($route)
{
$parameters = $route->parameters();
$path = $this->resolveRoutePath($route);

$path = preg_replace_callback('#/\{(.*?)\??\}#', function ($matches) use ($parameters)
{
$value = Arr::get($parameters, $name = $matches[1], trim($matches[0], '/'));

return ($name !== 'pageQuery') ? '/' .$value : '';

}, $route->uri());

$urlGenerator = $this->app['url'];

return $urlGenerator->to($path);
return $this->app['url']->to($path);
});

Paginator::currentPageResolver(function ($pageName = 'page') use ($route)
Expand All @@ -83,4 +73,23 @@ public function handle(Request $request, Closure $next)

return $next($request);
}

/**
* Resolve the parameters of a Route path.
*
* @param \Nova\Routing\Route $route
* @return string
*/
protected function resolveRoutePath(Route $route)
{
$parameters = $route->parameters();

return preg_replace_callback('#/\{(.*?)\??\}#', function ($matches) use ($parameters)
{
$value = Arr::get($parameters, $name = $matches[1], trim($matches[0], '/'));

return ($name !== 'pageQuery') ? '/' .$value : '';

}, $route->uri());
}
}

0 comments on commit bbaf5fc

Please sign in to comment.