feat(roles): tambah fitur relasi posisi pada role
- Tambahkan relasi posisi dengan menambahkan kolom `position_id` pada tabel roles melalui migrasi. - Perbarui fungsi pada `RolesController` untuk menyertakan posisi dalam proses CRUD. - Gunakan model `Position` untuk mendapatkan daftar posisi baik saat membuat maupun mengedit role. - Sesuaikan nama permission dari `roles.view` ke `roles.read`, `roles.store` ke `roles.create`, dan `roles.edit` ke `roles.update` agar konsisten. - Perbarui validasi di `RoleRequest` untuk mendukung input `position_id`. - Tambahkan properti `position_id` ke atribut `fillable` di model Role untuk mendukung mass assignment. - Buat fungsi relasi `position()` pada model Role untuk mereferensikan ke model Position. - Perbarui tampilan form role (`create.blade.php`): - Tambahkan dropdown untuk memilih posisi dalam form input. - Tampilkan informasi level posisi bersama dengan nama posisi dalam dropdown. - Sinkronisasi validasi dan nilai default sesuai dengan pengaturan posisi. - Perbaikan minor pada query pencarian data roles, menggunakan `whereRaw` untuk pencarian case-insensitive.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$tableNames = config('permission.table_names');
|
||||
|
||||
if (empty($tableNames)) {
|
||||
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
|
||||
}
|
||||
|
||||
Schema::table($tableNames['roles'], function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('position_id')->nullable()->after('guard_name');
|
||||
$table->foreign('position_id')
|
||||
->references('id')
|
||||
->on('positions')
|
||||
->onDelete('set null');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$tableNames = config('permission.table_names');
|
||||
|
||||
if (empty($tableNames)) {
|
||||
throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
|
||||
}
|
||||
|
||||
Schema::table($tableNames['roles'], function (Blueprint $table) {
|
||||
$table->dropForeign(['position_id']);
|
||||
$table->dropColumn('position_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user