Performing a query in eloquent, which lists the records in table a that are related to the records in table b, so far so good.
Additionally I need it to also list the records from a that are not related in b. Any suggestions?
Performing a query in eloquent, which lists the records in table a that are related to the records in table b, so far so good.
Additionally I need it to also list the records from a that are not related in b. Any suggestions?
In the Laravel documentation it mentions that the class
Illuminate\Database\Eloquent\Builder
has a method called doesntHave which would be the opposite ofhas
.In your case you could make the query you need like this: