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.
Laravel's paginator is integrated with the query builder and Eloquent ORM and provides convenient, easy-to-use pagination of database results out of the box. The HTML generated by the paginator is compatible with the Bootstrap CSS framework. There are several ways to paginate items.
The simplest is by using the paginatemethod on the query builderor an Eloquent query. The paginatemethod provided by Laravel automatically takes care of setting the proper limit and offset based on the current page being viewed by the user. By default, the current page is detected by the value of the ?pagequery string argument on the HTTP request.
In First step we have to create migration for items table using Laravel 5 php artisan command, so first fire bellow command: After this command you will find one file in following path database/migrations and you have to put bellow code in your migration file for create items table.
When calling the links method on a paginator instance, pass the view name as the first argument to the method: However, the easiest way to customize the pagination views is by exporting them to your resources/views/vendor directory using the vendor:publish command:
remove all() function, your code should be:
$content = content::paginate(10);
As suggested by Gouda Elalfy you should remove the call to all()
.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With