mardi 7 janvier 2020

Cannot delete data in other table linked with foreign key in Laravel

I have two table one is for role and other for its permission i want to delete role permission when i delete role. For that i have linked role table with role permission with the help of below code in migration, but it is not deleting data from role permission.

class Role extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
         Schema::create('role', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->foreign('id')->references('role_id')->on('role_permission')->onDelete('cascade');
        });
    }

Role Permission :

class CreateRolePermission extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('role_permission', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('role_id');
            $table->integer('module_id');
            $table->integer('permission');
        });
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire