8
votes

I used this way to make a pagination for my site, but I still get an error! I tried to solve and I searched a lot, didn't find a solution. I hope you can help me.

Controller -

class ContentController extends MasterController {


    public function content() {
$content = content::all()->paginate(10);  
$content->setPath('content'); //Customise Page Url
return view('content.boot',compact('content'));

}
}

view -

@extends('master')
@section('content')

@if(count($content) > 0 )

@foreach($content as $row)

<video width="330" controls>
    <source src="{{ asset('videos/' . $row['video'] )}}" type="video/mp4">
</video>
@endforeach
@endif

{!! $content->render() !!} 

@endsection

route -

Route::get('/', 'ContentController@content');

Error -

BadMethodCallException in Macroable.php line 81:
Method paginate does not exist.

3

3 Answers

15
votes

remove all() function, your code should be:

$content = content::paginate(10);  
7
votes

As suggested by Gouda Elalfy you should remove the call to all().

Explanation

The method paginate() is available on Eloquent\Builder which is what you implicitly have when you call content::paginage(10).

However content::all() returns a Collection or an array of Model, not a Builder.

4
votes

Here it explains how to do it https://laravel.com/docs/5.2/pagination and based on that you should do:
1) In your controller change the line $content = content::all()->paginate(10);
to be
$content = content::paginate(10);
2) In your view you could use this
{{ $content->appends(Request::except('page'))->links() }}
This will do what you want!!