Pagination in laravel 5.5

1

I'm performing a pagination of the data as follows:

Controller:

$brands = $this->brand::where('id', $filter_id)->paginate($this->total_page);

View:

{{ $brands->appends(['id' => isset($filter_id) ? $filter_id : ''])->links() }}

Here's the result:

Iwouldliketomakeitlooklikethis:

Do you know where I can change this number of links, leaving the range smaller?

    
asked by anonymous 09.10.2017 / 21:08

1 answer

1

To customize the page, we should tweak the structure of laravel,

We have to access the laravel file

vendor/laravel/framework/src/Illuminate/Pagination/UrlWindow.php

Leave your methods as follows:

public function getStart()
{
    return $this->paginator->getUrlRange(1, 1);
}

public function getFinish()
    {
        return $this->paginator->getUrlRange(
            $this->lastPage(),
            $this->lastPage()
        );
    }
public function getAdjacentUrlRange($onEachSide)
    {
        return $this->paginator->getUrlRange(
            $this->currentPage() - 1,
            $this->currentPage() + 1
        );
    }
protected function getSliderTooCloseToEnding($window)
    {
        $last = $this->paginator->getUrlRange(
            $this->lastPage() - (2),
            $this->lastPage()
        );

        return [
            'first' => $this->getStart(),
            'slider' => null,
            'last' => $last,
        ];
    }

protected function getSliderTooCloseToBeginning($window)
    {
        return [
            'first' => $this->paginator->getUrlRange(1, 3),
            'slider' => null,
            'last' => $this->getFinish(),
        ];
    }

And now the magic is done!

    
13.10.2017 / 20:38