Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

php - use illuminate/pagination outside laravel

I try to use laravel pagination in my custom CMS

the illuminate/pagination work, but not properly

this code for my controller work

       $cats= Category::paginate(2);

but when i want to calling the pagination link in this code in blade engine

{{$cats->links()}}

or 

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

or 

{{$cats->render()}}

I get this error

call_user_func() expects parameter 1 to be a valid callback, no array or string given (View: C:xampphtdocsgitrepomvcframwork
esourcesviewadminproductscategory.blade.php)

enter image description here

git project url https://github.com/mohammadZx/mvcframwork/tree/log

you can check project in github on log branch

I think this problem belongs to laravel pagination service provider but still i don't know how register laravel providers or fix this problem


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you have to register PaginationSerivceProvider. follow PaginationSerivceProvider in regsiter method and do required actions

Or

go to LengthAwarePaginator.php file and refactor a blade or view handler for this method with contained property you should know below method have all pagination system and just need to require in view handler

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...