Skip to content
Advertisement

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.

JavaScript

Advertisement

Answer

try whereDoesntHave

JavaScript

Edit:

You can also add new column aircons_count will old number of aircons for every order which will be faster than the above query and run the query like the following:

JavaScript

Note: make sure to add logic every time you add/remove aircon to an order

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement