In my project I have two tables (category and product) which are connected in relationship. When I try delete category which is assigned to the product, Laravel returned:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (
magazyn.products, CONSTRAINTproducts_article_id_foreignFOREIGN KEY (article_id) REFERENCESarticles(id)) (SQL: delete fromarticleswhereid= 23)
I know why laravel returns this error but I have a question: How do I create an information example: "You cannot delete this category, because it contains products"