diff --git a/app/Http/Middleware/MenuMiddleware.php b/app/Http/Middleware/MenuMiddleware.php
index 14e0c69..27c9d66 100644
--- a/app/Http/Middleware/MenuMiddleware.php
+++ b/app/Http/Middleware/MenuMiddleware.php
@@ -9,7 +9,6 @@ use Illuminate\Support\Facades\Auth;
class MenuMiddleware
{
-
public function handle($request, Closure $next)
{
$menu = Menu::new()
@@ -19,76 +18,34 @@ class MenuMiddleware
'data-widget' => 'treeview',
'role' => 'menu',
'data-accordion' => 'false'
- ]);
-
- $menu->html('
+ ])
+ ->html('
Halaman Utama
');
- // Ambil data menu utama
$user = Auth::guard('admin')->user();
$role = $user->roles->first();
$currentRoleId = $role ? $role->id : null;
- $menus = DB::select("
- SELECT m.*, rm.menu_id AS assigned_menu_id
- FROM menus m
- LEFT JOIN role_menu rm
- ON m.id = rm.menu_id
- WHERE m.parent_id IS NULL AND rm.role_id = '".$currentRoleId."'
- ORDER BY m.id
- ");
-
- foreach ($menus as $item) {
- // Ambil submenu jika ada
- $children = DB::select("
- SELECT m.*, rm.menu_id AS assigned_menu_id
- FROM menus m
- LEFT JOIN role_menu rm
- ON m.id = rm.menu_id
- WHERE m.parent_id = '".$item->id."' AND rm.role_id = '".$currentRoleId."'
- ORDER BY m.id
- ");
+ if ($currentRoleId) {
+ // Single query to get all authorized menus
+ $allMenus = DB::table('menus')
+ ->join('role_menu', 'menus.id', '=', 'role_menu.menu_id')
+ ->where('role_menu.role_id', $currentRoleId)
+ ->select('menus.*')
+ ->orderBy('order', 'ASC')
+ ->get();
-
+ // Organize menus into parents and children
+ $parents = $allMenus->where('parent_id', null);
+ $childrenByParent = $allMenus->whereNotNull('parent_id')
+ ->groupBy('parent_id');
- if (isset($children)) {
- // Menu dengan child
- $submenu = Menu::new()->addClass('nav nav-treeview');
-
- foreach ($children as $child) {
-
- $submenu->html(
- '' .
- '' .
- '' .
- '' . $child->title . '
' .
- '' .
- ''
- );
- }
- $menu->html(
- '' .
- '' .
- '' .
- '' . $item->title . '
' .
- '' .
- $submenu->render() .
- ''
- );
- } else {
- // Menu tanpa child
- $menu->html(
- '' .
- '' .
- '' .
- '' . $item->title . '
' .
- '' .
- ''
- );
+ foreach ($parents as $parent) {
+ $this->addMenuItems($menu, $parent, $childrenByParent->get($parent->id));
}
}
@@ -96,5 +53,36 @@ class MenuMiddleware
return $next($request);
}
-
-}
+
+ protected function addMenuItems($menu, $item, $children)
+ {
+ if ($children && $children->isNotEmpty()) {
+ $submenu = Menu::new()->addClass('nav nav-treeview');
+ foreach ($children as $child) {
+ $submenu->html($this->createMenuItem($child));
+ }
+
+ $menu->html(
+ '' .
+ '' .
+ '' .
+ '' . $item->title . '
' .
+ '' .
+ $submenu->render() .
+ ''
+ );
+ } else {
+ $menu->html($this->createMenuItem($item));
+ }
+ }
+
+ protected function createMenuItem($item)
+ {
+ return '' .
+ '' .
+ '' .
+ '' . $item->title . '
' .
+ '' .
+ '';
+ }
+}
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 22d26a8..a9a2156 100644
--- a/composer.json
+++ b/composer.json
@@ -11,6 +11,7 @@
"guzzlehttp/guzzle": "^7.9",
"intervention/image": "^3.9",
"laravel/framework": "^11.31",
+ "laravel/octane": "^2.6",
"laravel/tinker": "^2.9",
"laravel/ui": "^4.6",
"laravolt/avatar": "^6.0",
diff --git a/composer.lock b/composer.lock
index 64e194c..be6d833 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "5ba74d8866276fa9daa9d6c52fd9f690",
+ "content-hash": "2576aa0bcffcd93e0f78de10eefa63c1",
"packages": [
{
"name": "barryvdh/laravel-dompdf",
@@ -1430,6 +1430,94 @@
],
"time": "2024-10-27T10:15:54+00:00"
},
+ {
+ "name": "laminas/laminas-diactoros",
+ "version": "3.5.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/laminas/laminas-diactoros.git",
+ "reference": "143a16306602ce56b8b092a7914fef03c37f9ed2"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/laminas/laminas-diactoros/zipball/143a16306602ce56b8b092a7914fef03c37f9ed2",
+ "reference": "143a16306602ce56b8b092a7914fef03c37f9ed2",
+ "shasum": ""
+ },
+ "require": {
+ "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
+ "psr/http-factory": "^1.1",
+ "psr/http-message": "^1.1 || ^2.0"
+ },
+ "conflict": {
+ "amphp/amp": "<2.6.4"
+ },
+ "provide": {
+ "psr/http-factory-implementation": "^1.0",
+ "psr/http-message-implementation": "^1.1 || ^2.0"
+ },
+ "require-dev": {
+ "ext-curl": "*",
+ "ext-dom": "*",
+ "ext-gd": "*",
+ "ext-libxml": "*",
+ "http-interop/http-factory-tests": "^2.2.0",
+ "laminas/laminas-coding-standard": "~2.5.0",
+ "php-http/psr7-integration-tests": "^1.4.0",
+ "phpunit/phpunit": "^10.5.36",
+ "psalm/plugin-phpunit": "^0.19.0",
+ "vimeo/psalm": "^5.26.1"
+ },
+ "type": "library",
+ "extra": {
+ "laminas": {
+ "module": "Laminas\\Diactoros",
+ "config-provider": "Laminas\\Diactoros\\ConfigProvider"
+ }
+ },
+ "autoload": {
+ "files": [
+ "src/functions/create_uploaded_file.php",
+ "src/functions/marshal_headers_from_sapi.php",
+ "src/functions/marshal_method_from_sapi.php",
+ "src/functions/marshal_protocol_version_from_sapi.php",
+ "src/functions/normalize_server.php",
+ "src/functions/normalize_uploaded_files.php",
+ "src/functions/parse_cookie_header.php"
+ ],
+ "psr-4": {
+ "Laminas\\Diactoros\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "description": "PSR HTTP Message implementations",
+ "homepage": "https://laminas.dev",
+ "keywords": [
+ "http",
+ "laminas",
+ "psr",
+ "psr-17",
+ "psr-7"
+ ],
+ "support": {
+ "chat": "https://laminas.dev/chat",
+ "docs": "https://docs.laminas.dev/laminas-diactoros/",
+ "forum": "https://discourse.laminas.dev",
+ "issues": "https://github.com/laminas/laminas-diactoros/issues",
+ "rss": "https://github.com/laminas/laminas-diactoros/releases.atom",
+ "source": "https://github.com/laminas/laminas-diactoros"
+ },
+ "funding": [
+ {
+ "url": "https://funding.communitybridge.org/projects/laminas-project",
+ "type": "community_bridge"
+ }
+ ],
+ "time": "2024-10-14T11:59:49+00:00"
+ },
{
"name": "laravel/framework",
"version": "v11.35.1",
@@ -1645,6 +1733,96 @@
},
"time": "2024-12-12T18:25:58+00:00"
},
+ {
+ "name": "laravel/octane",
+ "version": "v2.6.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/laravel/octane.git",
+ "reference": "6d46153a04d73d07466bbb1f70d827614dc131eb"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/laravel/octane/zipball/6d46153a04d73d07466bbb1f70d827614dc131eb",
+ "reference": "6d46153a04d73d07466bbb1f70d827614dc131eb",
+ "shasum": ""
+ },
+ "require": {
+ "laminas/laminas-diactoros": "^3.0",
+ "laravel/framework": "^10.10.1|^11.0",
+ "laravel/prompts": "^0.1.24|^0.2.0|^0.3.0",
+ "laravel/serializable-closure": "^1.3|^2.0",
+ "nesbot/carbon": "^2.66.0|^3.0",
+ "php": "^8.1.0",
+ "symfony/console": "^6.0|^7.0",
+ "symfony/psr-http-message-bridge": "^2.2.0|^6.4|^7.0"
+ },
+ "conflict": {
+ "spiral/roadrunner": "<2023.1.0",
+ "spiral/roadrunner-cli": "<2.6.0",
+ "spiral/roadrunner-http": "<3.3.0"
+ },
+ "require-dev": {
+ "guzzlehttp/guzzle": "^7.6.1",
+ "inertiajs/inertia-laravel": "^1.3.2|^2.0",
+ "laravel/scout": "^10.2.1",
+ "laravel/socialite": "^5.6.1",
+ "livewire/livewire": "^2.12.3|^3.0",
+ "mockery/mockery": "^1.5.1",
+ "nunomaduro/collision": "^6.4.0|^7.5.2|^8.0",
+ "orchestra/testbench": "^8.21|^9.0",
+ "phpstan/phpstan": "^1.10.15",
+ "phpunit/phpunit": "^10.4",
+ "spiral/roadrunner-cli": "^2.6.0",
+ "spiral/roadrunner-http": "^3.3.0"
+ },
+ "bin": [
+ "bin/roadrunner-worker",
+ "bin/swoole-server"
+ ],
+ "type": "library",
+ "extra": {
+ "laravel": {
+ "aliases": {
+ "Octane": "Laravel\\Octane\\Facades\\Octane"
+ },
+ "providers": [
+ "Laravel\\Octane\\OctaneServiceProvider"
+ ]
+ },
+ "branch-alias": {
+ "dev-master": "2.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Laravel\\Octane\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Taylor Otwell",
+ "email": "taylor@laravel.com"
+ }
+ ],
+ "description": "Supercharge your Laravel application's performance.",
+ "keywords": [
+ "frankenphp",
+ "laravel",
+ "octane",
+ "roadrunner",
+ "swoole"
+ ],
+ "support": {
+ "issues": "https://github.com/laravel/octane/issues",
+ "source": "https://github.com/laravel/octane"
+ },
+ "time": "2025-01-28T15:16:08+00:00"
+ },
{
"name": "laravel/prompts",
"version": "v0.3.2",
@@ -7103,6 +7281,89 @@
],
"time": "2024-11-06T14:24:19+00:00"
},
+ {
+ "name": "symfony/psr-http-message-bridge",
+ "version": "v7.2.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/psr-http-message-bridge.git",
+ "reference": "03f2f72319e7acaf2a9f6fcbe30ef17eec51594f"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/psr-http-message-bridge/zipball/03f2f72319e7acaf2a9f6fcbe30ef17eec51594f",
+ "reference": "03f2f72319e7acaf2a9f6fcbe30ef17eec51594f",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=8.2",
+ "psr/http-message": "^1.0|^2.0",
+ "symfony/http-foundation": "^6.4|^7.0"
+ },
+ "conflict": {
+ "php-http/discovery": "<1.15",
+ "symfony/http-kernel": "<6.4"
+ },
+ "require-dev": {
+ "nyholm/psr7": "^1.1",
+ "php-http/discovery": "^1.15",
+ "psr/log": "^1.1.4|^2|^3",
+ "symfony/browser-kit": "^6.4|^7.0",
+ "symfony/config": "^6.4|^7.0",
+ "symfony/event-dispatcher": "^6.4|^7.0",
+ "symfony/framework-bundle": "^6.4|^7.0",
+ "symfony/http-kernel": "^6.4|^7.0"
+ },
+ "type": "symfony-bridge",
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Bridge\\PsrHttpMessage\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "PSR HTTP message bridge",
+ "homepage": "https://symfony.com",
+ "keywords": [
+ "http",
+ "http-message",
+ "psr-17",
+ "psr-7"
+ ],
+ "support": {
+ "source": "https://github.com/symfony/psr-http-message-bridge/tree/v7.2.0"
+ },
+ "funding": [
+ {
+ "url": "https://symfony.com/sponsor",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/fabpot",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2024-09-26T08:57:56+00:00"
+ },
{
"name": "symfony/routing",
"version": "v7.2.0",
diff --git a/routes/web.php b/routes/web.php
index c1b4899..1ea8a99 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -21,6 +21,7 @@ use App\Http\Controllers\Backend\BudgetControlController;
use App\Http\Controllers\Backend\ReportController;
use App\Http\Controllers\Master\RegionController;
use App\Http\Controllers\Master\CabangController;
+use Illuminate\Http\Request;
Auth::routes();
require __DIR__ . '/api.php';
@@ -197,4 +198,11 @@ Route::middleware(['auth:admin', 'menu'])->group(function () {
//Menu Role
Route::get('/auth/menu-tree/{id}', [MenuRoleController::class, 'index'])->name('auth.menurole.index');
Route::post('/auth/menu-tree/submit', [MenuRoleController::class, 'saveMenu'])->name('auth.menurole.submit');
-});
\ No newline at end of file
+});
+
+Route::get('/check-workers', function (Request $request) {
+ return response()->json([
+ 'octane_client' => app()->bound(\Laravel\Octane\Contracts\Client::class),
+ 'worker_pid' => getmypid(),
+ ]);
+});