How can I display pagination in laravel?(如何在 Laravel 中显示分页?)
问题描述
我使用 Laravel 5.6
我试试这个文档:
在视图 laravel 上,我添加:
{{ $products->links() }}
然后我上网查,结果为空
为什么结果为空?
有什么问题吗?
如果图片不显示,请访问:https://postimg.org/image/w39usbfrv/
你的控制器代码看起来像这样
$products = DB::table('products')->paginate(20);return view('admin.product.index', ['products' => $products ]);
您的查看页面代码如下
@foreach ($products as $product){{ $product->product_name}}@endforeach{{ $products->links() }}
注意:添加超过限制的项目以查看分页链接
I use laravel 5.6
I try this documentation : https://laravel.com/docs/5.6/pagination
My controller like this :
public function index()
{
$products = $this->product->list();
dd($products);
return view('admin.product.index',compact('products'));
}
My list function like this :
public function scopeList($query)
{
return $query->orderBy('updated_at', 'desc')->paginate(20);
}
If I dd($products);
, the result like this :
On the view laravel, I add this :
{{ $products->links() }}
Then I check on the web, the result empty
Why the result empty?
Is there something wrong?
If the image not display, access here : https://postimg.org/image/w39usbfrv/
your controller code will look like this
$products = DB::table('products')->paginate(20);
return view('admin.product.index', ['products' => $products ]);
your view page code look like this
@foreach ($products as $product)
{{ $product->product_name}}
@endforeach
{{ $products->links() }}
Note : Add more items more than your limit to view pagination links
这篇关于如何在 Laravel 中显示分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Laravel 中显示分页?


- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01