Reputation: 31
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
Reputation: 79
Pagination in laravel
make sure this in controller
use Illuminate\Pagination\Paginator;
paginator::sseBootstrap();
Upvotes: 0
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 theget
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
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
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