Paging in Laravel 5.5

Asked

Viewed 2,132 times

1

I am making a data pagination as follows:

Controller:

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

View:

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

This is the result:

inserir a descrição da imagem aqui

I’d like to make it look like this:

inserir a descrição da imagem aqui

You know where I can change this number of "links" making the interval shorter?

1 answer

1


To customize the page, we should stir a little the structure of the Laravel,

We have to access the file

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

leave your methods as the following:

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 that’s it, the magic is done!!!

  • If you have any questions or would like to know more about these methods I put myself at your disposal to help.

  • very well, it worked perfectly, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.