首页 > 解决方案 > 在 laravel 外使用照明/分页

问题描述

我尝试laravel pagination在我的自定义 CMS中使用

工作illuminate/pagination,但不正确

此代码用于我的控制器工作

       $cats= Category::paginate(2);

但是当我想在刀片引擎中调用这段代码中的分页链接时

{{$cats->links()}}

or 

{!! $cats->links() !!}

or 

{{$cats->render()}}

我收到这个错误

call_user_func() expects parameter 1 to be a valid callback, no array or string given (View: C:\xampp\htdocs\gitrepo\mvcframwork\resources\view\admin\products\category.blade.php)

在此处输入图像描述

git 项目网址 https://github.com/mohammadZx/mvcframwork/tree/log

你可以在 github 的 log 分支上检查项目

我认为这个问题属于laravel pagination service provider但我仍然不知道如何注册 laravel 提供者或解决这个问题

标签: phplaravelilluminate

解决方案


你必须注册PaginationSerivceProvider。遵循方法并执行所需PaginationSerivceProvider的操作regsiter

或者

转到LengthAwarePaginator.php文件并为具有包含属性的此方法重构刀片或视图处理程序,您应该知道下面的方法具有所有分页系统,只需要在视图处理程序中要求

public function render($view = null, $data = [])
    {
        return static::viewFactory()->make($view ?: static::$defaultView, 
          array_merge($data, [
            'paginator' => $this,
            'elements' => $this->elements(),
         ]));
    }


推荐阅读