Like this?
$posts = Post::doesntHave('comments')->get();
https://laravel.com/docs/8.x/eloquent-relationships#querying-relationship-absence
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a model with nested relations : Products.records.parts ...
I need to select all the products that have records without parts.
I thought this was it, but not so much:
$products = Product::whereIn('id', $this->selected)
->with(['records', function ($query) {
$query->whereDoesntHave('parts');
}])->get();
What did I miss?
Please or to participate in this conversation.