Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Components;
- use Illuminate\Pagination\LengthAwarePaginator;
- use Illuminate\Support\Arr;
- class SeoPaginator extends LengthAwarePaginator
- {
- /**
- * Remove page parameter from the first page URL.
- * Removing URL from active page.
- *
- * @param [type] $page
- * @return void
- */
- public function url($page)
- {
- if ($page <= 0) {
- $page = 1;
- }
- if ($this->currentPage == $page) {
- return null;
- }
- // If we have any extra query string key / value pairs that need to be added
- // onto the URL, we will put them in query string form and then attach it
- // to the URL. This allows for extra information like sortings storage.
- $parameters = [$this->pageName => $page];
- if (count($this->query) > 0) {
- $parameters = array_merge($this->query, $parameters);
- }
- // Remove 'page' parameter if it's 1
- if ($page == 1 && isset($parameters['page'])) {
- unset($parameters['page']);
- } else {
- $parameters['page'] = $page;
- }
- $result = $this->path()
- . (count($parameters) > 0
- ? (str_contains($this->path(), '?') ? '&' : '?')
- : '')
- . Arr::query($parameters)
- . $this->buildFragment();
- return trim($result, '?&');
- }
- }
- // In AppServiceProvider
- $this->app->alias(SeoPaginator::class, LengthAwarePaginator::class);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement