Skip to content

Commit

Permalink
changes for installation
Browse files Browse the repository at this point in the history
  • Loading branch information
subhobiswas committed Oct 7, 2024
1 parent e833b51 commit 1ecc869
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/database/migrations/create_permission_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePermissionTables extends Migration
return new class extends Migration
{
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name')->unique()->index();
$table->timestamps();
});
if (!Schema::hasTable('roles')) {
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name')->unique()->index();
$table->timestamps();
});
}

Schema::create('permissions', function (Blueprint $table) {
$table->id();
$table->string('name')->unique()->index();
$table->timestamps();
});
if (!Schema::hasTable('permissions')) {
Schema::create('permissions', function (Blueprint $table) {
$table->id();
$table->string('name')->unique()->index();
$table->timestamps();
});
}

Schema::create('role_permission', function (Blueprint $table) {
$table->id();
$table->foreignId('role_id')->constrained()->onDelete('cascade');
$table->foreignId('permission_id')->constrained()->onDelete('cascade');
});
if (!Schema::hasTable('role_permission')) {
Schema::create('role_permission', function (Blueprint $table) {
$table->id();
$table->foreignId('role_id')->constrained()->onDelete('cascade');
$table->foreignId('permission_id')->constrained()->onDelete('cascade');
});
}
}

public function down()
Expand All @@ -33,4 +39,4 @@ public function down()
Schema::dropIfExists('permissions');
Schema::dropIfExists('roles');
}
}
};

0 comments on commit 1ecc869

Please sign in to comment.