Open Ronan-Lenor opened 3 years ago
Here is a migration proposal to resolve it for the bugged version of voyager.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AlterMenuItem extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('menu_items', function (Blueprint $table)
{
$table->unsignedInteger('parent_id')->nullable()->change();
$table->foreign('parent_id')->references('id')->on('menu_items')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('menu_items', function (Blueprint $table)
{
$table->dropForeign(['parent_id']);
});
Schema::table('menu_items', function (Blueprint $table)
{
$table->integer('parent_id')->nullable()->change();
});
}
}
Laravel version
8.53
PHP version
7.4.14
Voyager version
1.x-dev 1102296
Database
MySQL 5.7.32
Description
Deleting a Parent MenuItem let its children with a a dead key in
parent_id
and they don't appear on the User Interface.Steps to reproduce
In the menu builder, if i create a parent (which in the database has a something like
id
=1
&parent_id
=null
) and that i associate a children to this parent (then the children hasid
=2
&parent_id
=1
) and that if i delete the parent, then the child remain in the databse with a dead key withparent_id
=1
(which doesn't exist anymore).Expected behavior
a Cascading deletation of all menu items children would be great
Screenshots
Additional context
No response