【问题标题】:Laravel 5.3, replace pagination links (<< and >>) with imagesLaravel 5.3,用图片替换分页链接(<< 和 >>)
【发布时间】:2017-03-07 12:57:02
【问题描述】:

如何用图片替换自定义 laravel 分页? 我还想在不重新加载页面的情况下获取下一组数据。 我的控制器看起来像这样。

class HomeController extends Controller
{
public function index()
{       
        $featured_products = DB::table('products')
        ->where('feature_type','=',3)
        ->orderBy('created_at','DESC')
        ->simplePaginate(4);


        $latest_products = DB::table('products')
        ->orderBy('created_at','DESC')
        ->simplePaginate(4);


        return View::make('pages.home')
         ->with(['featured_products'=>$featured_products,'latest_products'=>$latest_products]);
}

}

【问题讨论】:

    标签: php ajax laravel laravel-5 pagination


    【解决方案1】:

    在 5.3 中你可以customize pagination views

    在其他版本中,您可以尝试使用 CSS 覆盖它,或者您可以尝试 show links manually 而不是使用 $results-&gt;render() 方法:

    $results->count()
    $results->currentPage()
    $results->firstItem()
    $results->hasMorePages()
    $results->lastItem()
    $results->lastPage() (Not available when using simplePaginate)
    $results->nextPageUrl()
    $results->perPage()
    $results->previousPageUrl()
    $results->total() (Not available when using simplePaginate)
    $results->url($page)
    

    【讨论】:

      【解决方案2】:

      最简单的方法是编辑blade 文件以进行分页。

      首先,在您的控制台中运行:

      php artisan vendor:publish --tag=laravel-pagination
      

      然后转到resources/views/vendor/pagination/default.blade.php,你会看到:

      @if ($paginator->onFirstPage())
          <li class="disabled"><span>&laquo;</span></li>
      @else
          <li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">&laquo;</a></li>
      @endif
      
      ...
      
      @if ($paginator->hasMorePages())
          <li><a href="{{ $paginator->nextPageUrl() }}" rel="next">&raquo;</a></li>
      @else
          <li class="disabled"><span>&raquo;</span></li>
      @endif
      

      您可以将&amp;laquo;&amp;raquo; 替换为您要使用的图像。

      https://laravel.com/docs/5.3/pagination#customizing-the-pagination-view

      希望这会有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多