2 years ago

With a hasMany relationship, how to get only the parents without the children?

Posted 2 years ago by Smartapiary

I have models with hasMany relationship and everything works well. But I have a huge amount of children datas and when I want to load only a list of all the parents it take a long time (due to the quantity of children records and performances of my database) to get the result.

I would like to know I to fetch the a list of all the parents, but without querying the children.

Something like : Parents::all()->withoutAnyChildren

Please sign in or create an account to participate in this conversation.