首页 > 解决方案 > 为什么 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() !!}

所以我的问题是如何使它工作,链接不显示。感谢帮助。

标签: phplaravel

解决方案


你好,你需要把

{{ $files->links() }}

进入你的刀片文件。

links 方法将呈现指向结果集中其余页面的链接。这些链接中的每一个都已经包含正确的页面查询字符串变量。请记住,由 links 方法生成的 HTML 与 Bootstrap CSS 框架兼容。来源:https ://laravel.com/docs/5.8/pagination#displaying-pagination-results

Illuminate\View\View::render() 返回视图的字符串内容。


推荐阅读