'Get model only if relationship has data
I am working on a Laravel project and I have these two models User and Post:
user
-id
-name
-status
post
-id
-id_user
-name
What should I change from next line to have only User with at least one Post (I already created the one-to-many relationship in the models)?
$users = User::where('status', true)->get();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
