*/ function appLocales(): array { return config()->array('app.locales'); } /** * Get module */ function module(string $moduleName): ModuleContract { $moduleClass = 'App\\Modules\\'.$moduleName.'\\'.$moduleName.'Module'; return class_exists($moduleClass) ? (new $moduleClass) : emptyModule(); } /** * Empty module */ function emptyModule(): ModuleContract { return new EmptyModule; } /** * Modules directory path */ function modules_path(string $path = ''): string { return app_path('Modules/'.$path); } /** * Modules * * @return Collection */ function modules(bool $withDisabled = false): Collection { if (temp_cache()->has('modules')) { return temp_cache('modules'); } /** @var array */ $modulesDir = File::directories(modules_path()); $modules = collect(); foreach ($modulesDir as $modulePath) { $moduleName = Str::afterLast($modulePath, '/'); $moduleOptions = [ 'path' => $modulePath, 'name' => $moduleName.'Module', 'enabled' => module($moduleName)->isEnabled(), ]; // Include all if ($withDisabled) { $modules->push($moduleOptions); continue; } if ($moduleOptions['enabled']) { $modules->push($moduleOptions); } } temp_cache()->put('modules', $modules); return $modules; } /** * Temprory cache for single request */ function temp_cache(string $key = ''): mixed { $tempCache = cache()->driver('array'); return ($key !== '') ? $tempCache->get($key) : cache()->driver('array'); } /** * Log */ function logDB(): void { if (! app()->isLocal()) { return; } DB::listen(function ($query) { Log::info($query->sql, $query->bindings, $query->time); }); } /** * Get latest number * * @param string $tableName */ function getLatestNumber(string $tableName = 'incoming_letters', string $column = 'number'): int { $data = DB::table($tableName)->select(DB::raw("MAX(CAST(REGEXP_REPLACE({$column}, '[^0-9]', '') AS UNSIGNED)) AS max_number"))->first(); return intval($data->max_number) ?? 0; }