<?php
 namespace App\Helpers; use App\Models\Module; class ModuleConfig { public static function for(string $type, string $name): ?array { $module = Module::ofType($type) ->enabled() ->where('name', $name) ->with('settings') ->first(); return $module?->config; } public static function active(string $type): ?Module { return Module::ofType($type) ->enabled() ->orderBy('sort_order') ->orderBy('id') ->with('settings') ->first(); } public static function activeConfig(string $type): ?array { return self::active($type)?->config; } public static function resolved(string $type, string $name, array $declaredFields): array { $module = Module::ofType($type) ->where('name', $name) ->with('settings') ->first(); $db = $module?->config ?? []; $out = []; foreach ($declaredFields as $field) { $key = $field['key']; $out[$key] = array_key_exists($key, $db) ? $db[$key] : ($field['default'] ?? null); } return $out; } } 