php - Laravel 8 eloquent query delete
How to delete the aircon
in database when there is no any data.
Order
and Aircon
are many to many relationship.
$orders = Order::with('aircons', 'user')
->where('user_id', auth()->id())
->orWhere(//if order->aircons count == 0)->delete()
->get();
Answer
Solution:
try whereDoesntHave
$orders = Order::with('user')
->whereDoesntHave('aircons')
->where('user_id', auth()->id())
->get();
Source