Laravel pagination pretty URL

后端 未结 6 1093
孤街浪徒
孤街浪徒 2020-11-27 19:35

Is there a way to get a pagination pretty URL in Laravel 4?

For example, by default:

http://example.com/something/?page=3

And what

6条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 20:23

    For anyone that is using laravel version 5.6+

    You can pass additional parameters to set the page number.

    According to: https://laravel.com/api/5.6/Illuminate/Database/Eloquent/Builder.html#method_paginate

    Example:

    StoreController.php

    /**
     * Show sale item based on given page
     *
     * @param int $page
     * @return \Illuminate\Http\Response
     */
    public function showPage($page = 1)
    {
        $saleItems = SaleItem::paginate(10, array('*'), 'page', $page);
    
        ...
    }
    

    Then, in your blade template. You can just route( ... , array('page' => $page));

提交回复
热议问题