D
D
Danil Sysoev2021-02-08 13:55:14
Laravel
Danil Sysoev, 2021-02-08 13:55:14

How to select records that have N records from another eloquent table?

For example, there is a table with people and their purchased cars. How to choose people who have less than 3 purchased cars?
Is it possible to do this in one request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Georgy Eremeev, 2021-02-08
@YoungOldMan

https://laravel.com/docs/8.x/eloquent-relationship...

// Retrieve all posts that have three or more comments...
$posts = Post::has('comments', '>=', 3)->get();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question