Laravel 5.2 ajax分页显示错误"方法链接不存在"

时间:2017-04-18 05:35:19

标签: php ajax pagination laravel-5.2

我遇到了问题,

当我使用分页运行我的代码时出现错误

" Macroable.php第74行中的错误异常:方法链接不存在。 "

我的控制器代码

public function products(Request $request)
{
     $products      =   ProductLangModel::select('product.price','product.active','product_lang.*','product_image.image')
                                            ->join('product','product.id','=','product_lang.id_product')
                                            ->join('product_image','product_image.id_product','=','product_lang.id_product')
                                            ->where('idlang',$lng)
                                            ->paginate(4);

 if ($request->ajax()) {

            return view('frontend.product.List_productAjax', ['products' => $products])->render();  
        }

在视图中使用

                                        <nav class="woocommerce-pagination">
                                            <ul class="page-numbers">
                                                <li>
                                                    <span class="page-numbers">{{ $products->links() }}</span>
                                                </li>
                                            </ul>
                                        </nav>

经过大量搜索,它说使用render()而不是links(),但我仍然面临错误 &#34; Macroable.php第74行中的ErrorException:方法呈现不存在。 &#34;

当我dd($ products)时,我得到了结果

Collection {#475 ▼
  #items: array:10 [▼
    0 => ProductLangModel {#476 ▶}
    1 => ProductLangModel {#477 ▶}
    2 => ProductLangModel {#478 ▶}
    3 => ProductLangModel {#479 ▶}
    4 => ProductLangModel {#480 ▶}
    5 => ProductLangModel {#481 ▶}
    6 => ProductLangModel {#482 ▶}
    7 => ProductLangModel {#483 ▶}
    8 => ProductLangModel {#484 ▶}
    9 => ProductLangModel {#485 ▶}
  ]
}
  0 => ProductLangModel {#476 ▼
      #table: "product_lang"
      +timestamps: false
      #connection: null
      #primaryKey: "id"
      #keyType: "int"
      #perPage: 15
      +incrementing: true
      #attributes: array:12 [▶]
      #original: array:12 [▼
        "price" => "2.000"
        "active" => 1
        "id" => 3
        "id_product" => 2
        "idlang" => 1
        "name" => "VIN-Billing Name"
        "description_short" => "short desc_VIN-Billing Name"
        "description" => "hgfdg"
        "meta_title" => "fdgdfgd"
        "meta_description" => "gfhfgh"
        "meta_keywords" => "hfgh"
        "image" => "1488180547.jpg"
      ]
      #relations: []
      #hidden: []
      #visible: []
      #appends: []
      #fillable: []
      #guarded: array:1 [▶]
      #dates: []
      #dateFormat: null
      #casts: []
      #touches: []
      #observables: []
      #with: []
      #morphClass: null
      +exists: true
      +wasRecentlyCreated: false
    }

请找我解决方案

1 个答案:

答案 0 :(得分:0)

您是否通过此URL进行Ajax分页: - https://gist.github.com/tobysteward/6163902