@pb1uk you want to use having which is applied after the group by.
Review::groupBy('user_id')->havingRaw('COUNT(*) > 10')->get();
The equivalent of this
select * from `reviews` group by `user_id` having COUNT(*) > 10
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I'm in the process of rebuilding my website in laravel and i've come across a query that i'm struggling to recreate. Below is the query that I have currently, i'm doing a count and grouping by a user id and i only want to select ones that have a count higher than 10 - is it possible to recreate this in eloquent or would I have to go down the raw option?
SELECT * FROM ( SELECT count(*) as review_count FROM reviews GROUP BY user_id ) as vtable WHERE review_count > 10
Please or to participate in this conversation.