First commit
This commit is contained in:
44
database/migrations/2024_01_01_000001_create_roles_table.php
Normal file
44
database/migrations/2024_01_01_000001_create_roles_table.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000001_create_roles_table.php
|
||||
// Jadual roles untuk RBAC ringkas — admin, staff, viewer
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique(); // admin, staff, viewer
|
||||
$table->string('label'); // Admin Sistem, Kakitangan, Pengguna
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('user_roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('role_id')->constrained()->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
$table->unique(['user_id', 'role_id']);
|
||||
});
|
||||
|
||||
// Tambah kolum role pada users untuk single-role semudah mungkin
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('role')->default('viewer')->after('password');
|
||||
// role: admin | staff | viewer
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('role');
|
||||
});
|
||||
Schema::dropIfExists('user_roles');
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user