diff --git a/app/Models/Master/AccessMenu.php b/app/Models/Master/AccessMenu.php new file mode 100644 index 0000000..584f8c3 --- /dev/null +++ b/app/Models/Master/AccessMenu.php @@ -0,0 +1,15 @@ +hasMany(Menu::class,'parent_id','id'); + } + + public static function coreMenus($type, array $status = [1]): mixed + { + return Menu::where('parent_id', '=', 0) + ->where('menu_type', '=', $type) + ->whereIn('status', $status); + } + + public static function coreMenusByParent($id, array $status = [1]): mixed + { + return Menu::where('parent_id', '=', $id) + ->whereIn('status', $status); + } + + public static function getMenuByParentPosition($id, $type, array $active = [1], int $year = null): mixed + { + if ($year) { + $currYear = $year; + } else { + $currYear = date('Y'); + } + + return Menu::where('parent_id', '=', $id) + ->where('menu_type', '=', $type) + ->whereIn('status', $active) + ->union(Menu::coreMenus($type, $active)) + ->orderBy('ordering') + ->get(); + } + + /** + * @author alex.gz + * @created 08/12/2023 12:53 + * + * @param $type + * @param int|null $year + * + * @return mixed + */ + public static function getParentByType($type, int $year = null): mixed + { + if ($year) { + $currYear = $year; + } else { + $currYear = date('Y'); + } + + return Menu::where('parent_id', '=', 0) + ->where('menu_type', '=', $type) + ->union(Menu::coreMenus($type)) + ->orderBy('ordering') + ->get(); + } + + /** + * @author alex.gz + * @created 08/12/2023 18:07 + * + * @param $type + * @param int|null $year + * + * @return mixed + */ + public static function getMenuByYear($type, int $year = null): mixed + { + if ($year) { + $currYear = $year; + } else { + $currYear = date('Y'); + } + + return Menu::where('parent_id', '=', 0) + ->where('menu_type', '=', $type) + ->where('status', '=', true) + ->orderBy('ordering') + ->get(); + } + + /** + * @author alex.gz + * @created 08/12/2023 12:54 + * + * @param $type + * @param int|null $year + * + * @return mixed + */ + public static function getParentByTypeStatus($type, int $year = null): mixed + { + if ($year) { + $currYear = $year; + } else { + $currYear = date('Y'); + } + + return Menu::where('parent_id', '=', 0) + ->where('menu_type', '=', $type) + ->where('status', '=', true) + ->union(Menu::coreMenus($type)) + ->orderBy('ordering') + ->get(); + } + + public static function getMenuByParent($id, array $active = [1], int $year = null): mixed + { + if ($year) { + $currYear = $year; + } else { + $currYear = date('Y'); + } + + return Menu::where('parent_id', '=', $id) + ->union(Menu::coreMenusByParent($id, $active)) + ->whereIn('status', $active) + ->orderBy('ordering') + ->get(); + } + + public static function countMenuByYear(int $year): mixed + { + $model = Menu::where('status', '=', true); + return $model->count(); + } + + public static function getActiveById($id, int $year = null): mixed + { + if ($year) { + $currYear = $year; + } else { + $currYear = date('Y'); + } + + return Menu::where('id', '=', $id) + ->where('status', '=', true) + ->first(); + } + + public static function getActiveByPosition($type, int $year = null): mixed + { + if ($year) { + $currYear = $year; + } else { + $currYear = date('Y'); + } + + return Menu::where('menu_type', '=', $type) + ->where('status', '=', true) + ->union(Menu::coreMenus($type)) + ->orderBy('ordering') + ->get(); + } +} \ No newline at end of file diff --git a/database/migrations/2025_06_10_072532_create_menus_table.php b/database/migrations/2025_06_10_072532_create_menus_table.php new file mode 100644 index 0000000..2f27cc3 --- /dev/null +++ b/database/migrations/2025_06_10_072532_create_menus_table.php @@ -0,0 +1,37 @@ +id('MsMenuId'); + $table->foreignId('parent_id')->index()->default(0)->comment('idx menu_id'); + $table->string('title', 150); + $table->string('module', 150)->nullable(); + $table->string('url', 150)->nullable(); + $table->string('menu_type', 50)->index()->nullable()->comment('tb_menu_group alias'); + $table->string('menu_icons', 50)->nullable(); + $table->tinyInteger('ordering')->default(0); + $table->boolean('status')->default(true)->comment('True/False'); + $table->foreignId('created_by')->default(0); + $table->foreignId('updated_by')->default(0)->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('menus'); + } +}; diff --git a/database/migrations/2025_06_10_072636_create_groups_table.php b/database/migrations/2025_06_10_072636_create_groups_table.php new file mode 100644 index 0000000..92576b3 --- /dev/null +++ b/database/migrations/2025_06_10_072636_create_groups_table.php @@ -0,0 +1,32 @@ +id('MsGroupId'); + $table->string('name', 50)->unique(); + $table->string('alias', 50)->unique(); + $table->boolean('status')->default(true)->comment('True/False'); + $table->foreignId('created_by')->default(0); + $table->foreignId('updated_by')->default(0)->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('groups'); + } +}; diff --git a/database/migrations/2025_06_10_072637_create_access_menus_table.php b/database/migrations/2025_06_10_072637_create_access_menus_table.php new file mode 100644 index 0000000..d8e3f56 --- /dev/null +++ b/database/migrations/2025_06_10_072637_create_access_menus_table.php @@ -0,0 +1,41 @@ +id('MsAccessMenuId'); + $table->foreignId('ms_group_id')->comment('FK ms group'); + $table->string('module', 150)->nullable(); + $table->foreignId('ms_menu_id')->comment('FK tb_menu'); + $table->string('menu_group', 20)->nullable()->default('adminsidebar'); + $table->boolean('is_create')->default(false); + $table->boolean('is_read')->default(false); + $table->boolean('is_update')->default(false); + $table->boolean('is_delete')->default(false); + $table->boolean('is_verify')->default(false); + $table->boolean('is_approve')->default(false); + $table->boolean('is_download')->default(false); + $table->json('access')->nullable(); + $table->timestamps(); + $table->foreign('ms_menu_id')->references('MsMenuId')->on('ms_menu')->cascadeOnDelete(); + $table->foreign('ms_group_id')->references('MsGroupId')->on('ms_group')->cascadeOnDelete(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('access_menus'); + } +}; diff --git a/routes/web.php b/routes/web.php index f568ad0..bdb5a03 100644 --- a/routes/web.php +++ b/routes/web.php @@ -79,7 +79,7 @@ Route::get('/search', [SearchController::class, 'index'])->name('search'); // Route::get('/dashboard', function () { // return Inertia::render('dashboard'); // })->middleware(['auth','permission:Dashboard.index' ])->name('dashboard'); -Route::middleware(['auth', PermissionMiddleware::using('Dashboard.index')])->group(function () { +Route::middleware(['auth'])->group(function () { Route::get('/dashboard', DashboardController::class)->name('dashboard'); });