In laravel 5.1, is there any way to validate the referential integrity of the data?
I explain. I have 2 tables related by an FK Where Country can have several Departments (or States), how can I validate when a user wants to delete a Country that already has related Departments, show the user a message that indicates why it can not, instead of that the system sends the DELETE to the database and this generates the error of Foreign Key
SQLSTATE [23000]: Integrity constraint violation: 1451 Can not delete or update a parent row: a foreign key constraint fails ( sisoft
. departamento
, CONSTRAINT FK_Pais_idPais_departamento
FOREIGN KEY ( Pais_idPais
) REFERENCES pais
( idPais
) ON DELETE NO ACTION ON UPDATE NO ACTION) (SQL: delete from pais
where idPais
= 1)