Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 paginating

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.

like image 648
Fadee Avatar asked Jan 25 '16 11:01

Fadee


People also ask

What is paginator in Laravel?

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.

How to limit the number of pages in a Laravel query?

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.

How to create item table in Laravel 5 PHP artisan?

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.

How do I customize the pagination views in a paginator?

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:


2 Answers

remove all() function, your code should be:

$content = content::paginate(10);  
like image 191
Gouda Elalfy Avatar answered Sep 22 '22 14:09

Gouda Elalfy


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.

like image 27
Kdecherf Avatar answered Sep 19 '22 14:09

Kdecherf