Laravel page style replacement (add the first page and the last page)

Time:2019-11-8

Page style replacement of laravel (add first page and last page)


1. Customize a class (the code is as follows), place it as you like, and pay attention to the namespace.
2. Template output call {!! $data – > render (New \ app \ http \ controllers \ shmilythreepresenter ($data))!}
Final style

Implementation code

_

<?php

//Create and inherit from the illuminate \ pagination \ bootstrapthreepresenter class. Here I put the class under controllers. You need to modify the methods of the bootstrapthreepresenter class to override the methods. If you feel that the default bootstrap style does not match the style of your project, you can customize the style.
namespace App\Http\Controllers;
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
use Illuminate\Contracts\Pagination\Presenter as PresenterContract;

class ShmilyThreePresenter extends \Illuminate\Pagination\BootstrapThreePresenter
{
    /**
     * Convert the URL window into Bootstrap HTML.
     *
     * @return string
     */
    public function render()
    {
        if ($this->hasPages()) {
            return sprintf(
                '< UL class = "am paging" >% s% s% s% s < / UL >', // custom class style
                $this - > firstpage(), // add homepage method
                $this - > getpreviousbutton ('previous'),
                $this->getLinks(),
                $this - > getnextbutton ('next page '),
                $this - > last() // add end page method
            );
        }

        return '';
    }

    /**
     * Get HTML wrapper for an available page link.
     *
     * @param  string  $url
     * @param  int  $page
     * @param  string|null  $rel
     * @return string
     */
    protected function getAvailablePageWrapper($url, $page, $rel = null)
    {
        $rel = is_null($rel) ? '' : ' rel="'.$rel.'"';

        return '<li><a href="'.htmlentities($url).'"'.$rel.'>'.$page.'</a></li>';
        //Here Li tag can add your own class style
    }

    /**
     * Get HTML wrapper for disabled text.
     *
     * @param  string  $text
     * @return string
     */
    protected function getDisabledTextWrapper($text)
    {
        return '<li class="disabled"><span>'.$text.'</span></li>';
    }

    /**
     * Get HTML wrapper for active text.
     *
     * @param  string  $text
     * @return string
     */
    protected function getActivePageWrapper($text)
    {
        return '<li class="active"><span>'.$text.'</span></li>';
    }


    /**
     * Get the next page pagination element.
     *
     * @param  string  $text
     * @return string
     */
     //New homepage method
    Public function firstpage ($text = 'first page')
    {
        // If the current page is greater than or equal to the last page, it means we
        // can't go any further into the pages, as we're already on this last page
        // that is available, so we will make it the "next" link style disabled.
        if ($this->paginator->currentPage() <= 1) {
            return $this->getDisabledTextWrapper($text);
        }
        $url = $this->paginator->url(1);

        return $this->getPageLinkWrapper($url, $text, 'first');
    }

    /**
     * Get the next page pagination element.
     *
     * @param  string  $text
     * @return string
     */
     //New end page method
    Public function last ($text = 'last page')
    {
        // If the current page is greater than or equal to the last page, it means we
        // can't go any further into the pages, as we're already on this last page
        // that is available, so we will make it the "next" link style disabled.

        $url = $this->paginator->url($this->paginator->lastPage());

        return $this->getPageLinkWrapper($url, $text, 'last');
    }

}

Recommended Today

The use of progressbarcontrol, a progress bar control of devexpress – Taking ZedGraph as an example to add curve progress

scene WinForm control – devexpress18 download installation registration and use in vs: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100061243 When using ZedGraph to add curves, the number of curves is slower if there are many cases. So in the process of adding curve, the progress needs to be displayed, and the effect is as follows     Note: Blog home page:https://blog.csdn.net/badao_liumang_qizhi […]