繁体   English   中英

当我将分页链接回显到 html 时,如何修复 Method Illuminate\Support\Collection::links 不存在(错误)?

[英]How to fix Method Illuminate\Support\Collection::links does not exist (Error) when i echo out the pagination link to the html?

这是我第一次在我的分页链接上遇到这个问题,我真的不明白为什么当我检索分页链接时这个错误显示在我的刀片上。 为了更好地理解,我将向您展示我已经在我的项目中创建的示例 controller 和 html 页面。 这里的主要目标是对已经插入数据库表的列表产品进行分页。

Laravel 版本:5.8

https://laravel.com/docs/7.x/pagination#paginating-query-builder-results

方法 Illuminate\Support\Collection::links 不存在。 (查看:C:\xampp\htdocs\waps_project_app\resources\views\management\waps\product_history.blade.php)

Html:

<div style="margin-top:50px;">
<h3>Product History</h3>
<table  class="table table-striped table-bordered" style="width:100%">
    <thead>
        <tr style="font-size:12px;">
            <th>Category</th>
            <th>Item</th>
            <th>Qty</th>
            <th>Price</th>
            <th>Date</th>
        </tr>
    </thead>
    <tbody>
        @foreach($data as $product_data)
            <tr class="product_details" >
                <td class="item_code" style="font-size:12px;">{{$product_data->posting_category}}</td>
                <td class="item_name" style="font-size:12px;">{{$product_data->item_name}}</td>
                <td style="font-size:12px;">{{$product_data->item_qty}}</td>
                <td style="font-size:12px;">{{number_format($product_data->item_price,2)}}</td>
                <td style="font-size:12px;">{{$product_data->created_at}}</td>
            </tr>
        @endforeach
    </tbody>
    {{ $data->links() }}
</table>

Controller:

public function product_history() {

    $product_table = DB::table('product_basic_info')->get();

    return view('/management/waps/product_history',['data' =>$product_table]);
}

I think you are calling wrong method in your controller, function below in controller suppose to use paginate() function of laravel, only when you call that function, you would be able to use function links() to render pagination in your blade. 您可以查看 laravel 文档Laravel 分页 我希望它会有所帮助。

public function product_history() {

    $product_table = DB::table('product_basic_info')->paginate();

    return view('/management/waps/product_history',['data' =>$product_table]);
}

你必须像这样改变

$product_table = DB::table('product_basic_info')->paginate(15);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM