Aman Baweja
Aman Baweja

Reputation: 31

Pagination in laravel

I am trying to create pagination in laravel but its not working.

Here's the code :

$result=DB::table('sample')
            ->select()
            ->where('id','=',1)->orWhere('id','=',2)
            ->get()->paginate(10);
        return $result;

Upvotes: 1

Views: 160

Answers (4)

Manmohan Aeir
Manmohan Aeir

Reputation: 79

Pagination in laravel

make sure this in controller

use Illuminate\Pagination\Paginator;

**in service provider **
paginator::sseBootstrap();

enter image description here


enter image description here

enter image description here

Upvotes: 0

Alexey Mezenin
Alexey Mezenin

Reputation: 163968

When you're using get() or paginate() methods, you will get a collection instead of Eloquent object.

All multi-result sets returned by Eloquent are instances of the Illuminate\Database\Eloquent\Collection object, including results retrieved via the get method or accessed via a relationship.

When you're chaining get()->paginate(), you're trying to use paginate() method on a collection which will never work.

So, just use it without get():

$result = DB::table('sample')
            ->where('id', 1)
            ->orWhere('id', 2)
            ->paginate(10);

Upvotes: 2

RAUSHAN KUMAR
RAUSHAN KUMAR

Reputation: 6004

why you are using get() with pagination, remove this and write your query as

$result=DB::table('sample')
        ->select()
        ->where('id','=',1)->orWhere('id','=',2)
        ->paginate(10);
return $result;

Upvotes: 1

Aditya Singh
Aditya Singh

Reputation: 724

Try this :

$result=DB::table('sample')
            ->select()
            ->where('id','=',1)->orWhere('id','=',2)
            ->paginate(10);
        return $result;

Paginate will not work with get

Upvotes: 3

Related Questions