Let's say we have Table A, B and C (with their timestamps accordingly)
Table ZZ
id
some_fieldZ
Table YY
id
some_fieldY
Table XX
id
b_id
a_id
some_fieldX
Schema::table('XX', function (Blueprint $table) {
$table->foreign('ZZ')->references('id')->on('ZZ')->onDelete('cascade');
$table->foreign('YY')->references('id')->on('YY')->onDelete('cascade');
});
Is it possible to, whenever a record in YY or ZZ is deleted, to XX delete accordingly (and possibly YY/ZZ) without changing its structure (switching one of the FK from one table to another)?
Edit: Adding a line to the delete function the other record according to an id or having an Observer is two of the solutions I'm thinking just trying to explore other possible ways to achieve it