Laravel 5.2 paginating
Solution 1
remove all() function, your code should be:
$content = content::paginate(10);
Solution 2
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
.
Solution 3
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!!
Fadee
Updated on July 23, 2022Comments
-
Fadee almost 2 years
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. -
Fadee over 8 yearsthanks a lot , helped me , but now it appears behind the videos its sticky lets say , how can I make it in the bottom ? thanks
-
Fadee over 8 yearsthanks a lot , helped me , but now it appears behind the videos its sticky lets say , how can I make it in the bottom ? thanks