php - 为什么 Laravel 简单分页不起作用?
问题描述
这是我的控制器
class PageController extends Controller
{
public function showImageUrl (Request $req){
$directory = '/public/testukas/';
$files = collect(Storage::files($directory))->simplePaginate(8);
return view('welcome')->with('files',$files);
}
以及来自我的 appServiceprovider 的这段代码
if (!Collection::hasMacro('simplePaginate')) {
Collection::macro('simplePaginate',
function ($perPage = 15, $page = null, $options = []) {
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
return (
new Paginator(
$this->forPage($page, $perPage),
$perPage,
$page,
$options
)
)->withPath('');
});
}
在刀片模板中,我使用它来调用链接
{!! $files->render() !!}
所以我的问题是如何使它工作,链接不显示。感谢帮助。
解决方案
你好,你需要把
{{ $files->links() }}
进入你的刀片文件。
links 方法将呈现指向结果集中其余页面的链接。这些链接中的每一个都已经包含正确的页面查询字符串变量。请记住,由 links 方法生成的 HTML 与 Bootstrap CSS 框架兼容。来源:https ://laravel.com/docs/5.8/pagination#displaying-pagination-results
Illuminate\View\View::render() 返回视图的字符串内容。
推荐阅读
- python - 无法运行snakeviz。这里可能有什么问题?
- android - 私人政策链接不起作用 google sigin library android
- javascript - JS - then 与 async / await 返回值
- java - Weld-Junit 中 TimerService 的处理
- reactjs - React setState 不更新组件
- progressive-web-apps - 使用 PWA Shortcuts 时,是否可以本地化快捷方式名称?
- python - 如何使用 beautifulsoup 从 div 类中抓取内容
- dataframe - 如何对超过 50 个类别的列进行编码
- powershell - 从任务计划程序运行时,将文件上传到 SharePoint 的 PowerShell 脚本不起作用
- react-native - 使用 react-native-community/datetimepicker 日期和时间未显示