Performing a query in eloquent, which lists the records of the table to which they are related to the records in table b, up there well.
Additionally I need you to also list the records of a that are not related in b. Any suggestions?
Performing a query in eloquent, which lists the records of the table to which they are related to the records in table b, up there well.
Additionally I need you to also list the records of a that are not related in b. Any suggestions?
In Laravel's documentation he mentions that the class Illuminate\Database\Eloquent\Builder
has a method called doesntHave that would be the opposite of has
.
In your case you could make the query you need like this:
$noRelated = MoldelA::doesntHave('ModelB')->get();