create feat management role menu
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('role_menu', function (Blueprint $table) {
|
||||
$table->boolean('allow_show')->default(true)->after('menu_id');
|
||||
$table->boolean('allow_create')->default(true)->after('allow_show');
|
||||
$table->boolean('allow_update')->default(true)->after('allow_create');
|
||||
$table->boolean('allow_destroy')->default(true)->after('allow_update');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('role_menu', function (Blueprint $table) {
|
||||
$table->dropColumn(['allow_show','allow_create', 'allow_update', 'allow_destroy']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -71,7 +71,7 @@ class UsersRoleMenuSeeder extends Seeder
|
||||
];
|
||||
|
||||
foreach ($parent_menus as $parent_menu) {
|
||||
Menu::create($parent_menu);
|
||||
Menu::firstOrCreate(['name' => $parent_menu['name']], $parent_menu);
|
||||
}
|
||||
|
||||
// Attach Menus to Roles
|
||||
@@ -85,21 +85,7 @@ class UsersRoleMenuSeeder extends Seeder
|
||||
$dataSettings = Menu::where('name', 'Data Settings')->first();
|
||||
$data = Menu::where('name', 'Data')->first();
|
||||
|
||||
// Superadmin gets all menus
|
||||
$superadmin->menus()->attach([$dashboard->id, $master->id, $settings->id, $dataSettings->id, $data->id]);
|
||||
|
||||
// Admin gets limited menus
|
||||
$admin->menus()->attach([$dashboard->id, $master->id, $settings->id]);
|
||||
|
||||
// Operator gets only basic menus
|
||||
$operator->menus()->attach([$dashboard->id, $data->id]);
|
||||
|
||||
// Attach User to role super admin
|
||||
User::findOrFail(1)->roles()->attach($superadmin->id);
|
||||
|
||||
// create children menu
|
||||
|
||||
// dashboard children
|
||||
$children_menus = [
|
||||
[
|
||||
"name" => "Dashboard Pimpinan",
|
||||
@@ -143,13 +129,6 @@ class UsersRoleMenuSeeder extends Seeder
|
||||
"parent_id" => $settings->id,
|
||||
"sort_order" => 3,
|
||||
],
|
||||
[
|
||||
"name" => "Assign Role Menu",
|
||||
"url" => "roles.index",
|
||||
"icon" => null,
|
||||
"parent_id" => $settings->id,
|
||||
"sort_order" => 4,
|
||||
],
|
||||
[
|
||||
"name" => "Setting Dashboard",
|
||||
"url" => "data-settings.index",
|
||||
@@ -167,7 +146,48 @@ class UsersRoleMenuSeeder extends Seeder
|
||||
];
|
||||
|
||||
foreach ($children_menus as $child_menu) {
|
||||
Menu::create($child_menu);
|
||||
Menu::firstOrCreate(['name' => $child_menu['name']], $child_menu);
|
||||
}
|
||||
|
||||
$dashboard_pimpinan = Menu::where('name', 'Dashboard Pimpinan')->first();
|
||||
$dashboard_pbg = Menu::where('name', 'Dashboard PBG')->first();
|
||||
$users = Menu::where('name', 'Users')->first();
|
||||
$syncronize = Menu::where('name', 'Syncronize')->first();
|
||||
$setting_menu = Menu::where('name', 'Menu')->first();
|
||||
$setting_role = Menu::where('name', 'Role')->first();
|
||||
$setting_dashboard = Menu::where('name', 'Setting Dashboard')->first();
|
||||
$setting_pbg = Menu::where('name', 'PBG')->first();
|
||||
|
||||
// Superadmin gets all menus
|
||||
$superadmin->menus()->sync([
|
||||
$dashboard->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$master->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$settings->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$dataSettings->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$data->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$dashboard_pimpinan->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$dashboard_pbg->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$users->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$syncronize->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$setting_menu->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$setting_role->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$setting_dashboard->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$setting_pbg->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
]);
|
||||
|
||||
// Admin gets limited menus
|
||||
$admin->menus()->sync([
|
||||
$dashboard->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$master->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$settings->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
]);
|
||||
|
||||
// Operator gets only basic menus with full permissions
|
||||
$operator->menus()->sync([
|
||||
$dashboard->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
$data->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
|
||||
]);
|
||||
// Attach User to role super admin
|
||||
User::findOrFail(1)->roles()->sync([$superadmin->id]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user