Laravel whereDoesntHave() – multiple OR conditions

You can use doesntHave and specify the boolean operator:

$products = Product::doesntHave('categories')->doesntHave('countries', 'or')->get();

Actually you only need whereDoesntHave if you want to pass in a closure to filter the related models before checking if any of them exist. In case you want to do that you can pass the closure as third argument:

$products = Product::doesntHave('categories', 'or', function($q){
    $q->where('active', false);
})->doesntHave('countries', 'or')->get();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)