Skip to content
Advertisement

Problem with deleting items from pivot table

I am building project for learning purposes in oop php where I create properties/ads, and I have three tables, properties, photos and property_photo. My goal is when I click on delete button to delete properties at the same time to remove those photos that are connected to properties through pivot table, but when I try that I only delete properties from properties table and photos and ids in pivot table remain in database. I’m having difficulties writing sql query in my model. Any help is appreciated. Here is my code:

AdModel.php

AdsController.php

Advertisement

Answer

First delete from photos:

After that:

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