laravel修改分页样式并且把«和»改成上一页下一页

Song3887 次浏览0个评论2017年10月21日

在laravel中,默认的«和»确实看起来比较不好看,有时候我们需要把他们替换成中文的上一页下一页?其实很方便,最近有几个人问我,所以我整理一下发出来,当然这不是唯一的解决办法哈,但是它确实能解决问题。

laravel5.3以下修改办法

1、找到文件/vendor/laravel/framework/src/Illuminate/Pagination/BootstrapThreeNextPreviousButtonRendererTrait.php,打开以后把代码改成如下所示:
<?php

namespace Illuminate\Pagination;

trait BootstrapThreeNextPreviousButtonRendererTrait
{
    /**
     * Get the previous page pagination element.
     *
     * @param  string  $text
     * @return string
     */
    public function getPreviousButton($text = '上一页')
    {
        // If the current page is less than or equal to one, it means we can't go any
        // further back in the pages, so we will render a disabled previous button
        // when that is the case. Otherwise, we will give it an active "status".
        if ($this->paginator->currentPage() <= 1) {
            return $this->getDisabledTextWrapper($text);
        }

        $url = $this->paginator->url(
            $this->paginator->currentPage() - 1
        );

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

    /**
     * Get the next page pagination element.
     *
     * @param  string  $text
     * @return string
     */
    public function getNextButton($text = '下一页')
    {
        // 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->hasMorePages()) {
            return $this->getDisabledTextWrapper($text);
        }

        $url = $this->paginator->url($this->paginator->currentPage() + 1);

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

好了,现在刷新一下我们的分页,看看是不是变成上一页下一页了?

laravel 5.3以上修改方法

其实修改方法一样,只是文件位置不同了,我查看5.5的位置为resources/views/vendor/pagination/default.blade.php,只需要在这里修改即可。

相对来说5.3以上配置更加方便。

提交评论

请登录后评论

用户评论

    当前暂无评价,快来发表您的观点吧...

更多相关好文

    当前暂无更多相关好文推荐...