m.alinasab's avatar

how to get posts via category with pagination

hello .

i want to get posts from category id ( 1 , 2 , 3 ) and pagination for posts relation .

table Stractur :

Posts id | title | text

category_post relationship category_id | post_id

Category id | name

my Code is : Category::whereIn('id', [1 , 2 , 3])->with('posts')->paginate()

but Pagination Dont work only posts . if posts not exist from relation but pagination is exists !

0 likes
2 replies
aurawindsurfing's avatar

That is because you do not tell how many results per page you want:

$users = DB::table('users')->paginate(15);

Please or to participate in this conversation.