Wednesday, March 8, 2017

Eloquent - Has() with constraint

How do I add a constraint to the has() method on eloquent ?

Let's say, it want to retrieve all posts with at least 3 comments from John. How can I do that ?

Non-working example of expected code:

$posts = Post::has('comments', '>=', 3)->where('author', 'John')->get();

Can I achieve the same result another way (not using has())?



via Ruben

Advertisement