Answer the question
In order to leave comments, you need to log in
Why is the associated record not being deleted in the table?
There are 3 tables:
pictures , sections and catalogs The catalog
model is related to belongsTo with pictures and hasMany with sections
So it makes sense that a catalog can have photos and many sections.
Sections, in turn, can also have a photo and the section model is also associated with the belongsTo photo
and another section belongs to the directory, so to find out which one I added to the section model and belongsTo to the directory.
But the problem with the removal, I added to the events according to the documentation in the AppServiceProvider for the sections:
Section::deleting(function ($section) {
$section->pictures()->delete();
});
public function boot()
{
// Удаляем фото при удалении раздела
Section::deleting(function ($section) {
$section->pictures()->delete();
});
// Удаляем каталог и его фото и разделы и фото разделов при удалении каталога
Catalog::deleting(function ($catalog) {
$catalog->pictures()->delete();
$catalog->sections()->delete();
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question