runningInConsole() && Schema::hasTable('settings')) { $rawSettings = Setting::pluck('value', 'key')->toArray(); View::share('setting', (object) $rawSettings); } // 3. VIEW COMPOSER (Fungsi Notifikasi Stok Tetap Berjalan) $alertViews = ['layouts.app', 'layouts.navigation-sidebar', 'dashboard', 'pages.*']; View::composer($alertViews, function ($view) { $stockData = Cache::remember('low_stock_alerts', 600, function () { $lowMedicines = Medicine::where('qty', '<', 5)->get(['nama_obat', 'qty', 'unit']); $lowFoods = Food::where('qty', '<', 5)->get(['nama_makanan', 'qty', 'unit']); return [ 'lowStockMedicines' => $lowMedicines, 'lowStockFoods' => $lowFoods, 'totalAlerts' => $lowMedicines->count() + $lowFoods->count(), ]; }); $view->with($stockData); }); // 4. SISTEM OTORISASI GLOBAL (Gate Permission) Gate::define('check-access', function ($user, $module, $permission) { // Dukungan akun legacy yang masih menyimpan role sebagai string. if ($user->getRawOriginal('role') === 'admin') { return true; } if (!$user->role_id) { return false; } $role = $user->roleModel; if ($role?->slug === 'admin') { return true; } $column = str_starts_with($permission, 'can_') ? $permission : 'can_' . $permission; try { return \App\Models\RolePermission::where('role_id', $user->role_id) ->where('module_slug', $module) ->where($column, 1) ->exists(); } catch (\Throwable $e) { return false; } }); } }