B
B
BonBon Slick2017-02-02 12:51:52
Laravel
BonBon Slick, 2017-02-02 12:51:52

Zeroing the category_id field in the products table if the category is deleted?

Laravel oneToMany. The products table has a category_id field . At the moment, if you delete the category , then there is a check when parsing the product category, if there is such a category, display its name. However, the category_id field is still populated .

->onDelete('cascade');
// мне не надо удалять продукты если категория удалена

How to reset all fields with the category_id of a category that has been deleted without crutches and pivot tables ?
//костыль в функции удаления категории будет что - то в духе
DB::table('products')->where('category_id', $current_deleting_cat_id)->update(['category_id', null]));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question