I have a Post table with the following fields (id, name, state_id, city_id, category_id, subcategory_id) and PostPhoto table with the following fields (id, photo_url, post_id)
The Post Model has
public function user(){
return $this->belongsTo(User::class);
}
public function category(){
return $this->belongsTo(Category::class);
}
public function subCategory(){
return $this->hasOne(SubCategory::class);
}
public function photos(){
return $this->hasMany(PostPhoto::class);
}
public function city(){
return $this->belongsTo(City::class);
}
and PostPhoto Model has
public function post()
{
return $this->belongsTo(Post::class);
}
Now if I want to delete a particular post, it'll fail due to foreign key constrains. How do I delete the Post together with postphotos associated with it completely from database. And each post can have multiple photos also. Please any suggestion will be appreciated. Thanks