Reputation: 231
I developed one API(displayBlogs) which is responsible for getting data from database ,i want to apply pagination for displayBlogs api,for that i installed require package but i am unable to apply a pagination on that query(if i don't use get() method then pagination working) ,please help me to fix this issue..
UserController.php
public function displayBlogs(){
$user = new BlogModel();
$token = JWTAuth::getToken();
$id = JWTAuth::getPayload($token)->toArray();
$user->user_id = $id["sub"];
return DB::table('blogs_table')->where('user_id', $user->user_id)->get()->paginate(3);
}
Upvotes: 1
Views: 699
Reputation: 367
just use paginate only
public function displayBlogs(){
$user = new BlogModel();
$token = JWTAuth::getToken();
$id = JWTAuth::getPayload($token)->toArray();
$user->user_id = $id["sub"];
return DB::table('blogs_table')->where('user_id', $user->user_id)->paginate(3);
}
Upvotes: 2