How to limit the count of rows for a specific foreign key value in Laravel

How to limit the count of rows for a specific foreign key value in Laravel

We have a posts table and user_id is the foreign key For example, I want to choose posts for these users

We have a posts table and user_id is the foreign key For example, I want to choose posts for these users

$users=[1,2,13,16,17,19];
$posts = Post::whereIn('user_id', $users)->paginate(10);

But I want the user 1 and 2 only have two posts in the output, for the rest of the users there is not a limited number of posts.

Note: User 1 and 2 are not always within the $users array, and due to the condition, one or both of them may not be in the array.

Do you have a solution for me?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Laravel 5.8 Tutorial: Build your First CRUD App with Laravel and MySQL (PHP 7.1+)

Laravel 5.8 Tutorial: Build your First CRUD App with Laravel and MySQL (PHP 7.1+)

How To Set Up Laravel App on Docker, With NGINX and MySQL

Deploying Your Laravel App on Docker, With NGINX and MySQL ... The original post was also uploaded here: Laravel Application on Docker.

Top Laravel Development Companies Reviews

Among the list of Best Laravel development companies, TopDevelopers has chosen the most acclaimed laravel developers for the visitors so as to make them avail the extremely wonderful service ever offered. The web development companies listed here...