I am using Laravel php framework and I build my table like this
Schema::create('template_blocks', function (Blueprint $table) {
$table->increments('id');
$table->integer('content_template_id')->unsigned();
$table->string('type')->nullable();
$table->integer('order')->default(0)->unsigned();
$table->integer('parent')->nullable();
$table->text('meta')->nullable();
$table->timestamps();
$table->foreign('content_template_id')->references('id')->on('templates')->onDelete('cascade')->onUpdate('cascade');
});
As you see I have:
$table->integer('parent')->nullable();
which points to another row in the same table that is the parent. When I delete the parent I would like mysql to also delete children, the same way that it cascades delete when you delete a row in foriegn table that has relationship with current table.
Is this possible with mysql or would I have to delete these manually on the server when I delete the parent? Having mysql do it would be best but if it can't be done then please let me know.