*/ function appLocales(): array { return config()->array('app.locales'); } /** * Return modular repo */ function modular(): ModuleRepository { return app(ModuleRepository::class); } /** * Modules directory path */ function modules_path(string $path = ''): string { return modular()->path().'/'.$path; } /** * Get module */ function module(string $moduleName): ModuleContract { return modular()->module($moduleName); } /** * Modules * * @return Collection */ function modules(bool $withDisabled = false): Collection { return $withDisabled ? modular()->allModules() : modular()->modules(); } /** * Empty module */ function emptyModule(): ModuleContract { return modular()->emptyModule(); } /** * Temprory cache for single request * * @return ($key is '' ? CacheRepository : mixed) */ function temp_cache(string $key = ''): mixed { $tempCache = cache()->driver('array'); return ($key === '') ? $tempCache : $tempCache->get($key); } /** * Log */ function logDB(): void { if (! app()->isLocal()) { return; } DB::listen(function ($query) { Log::info($query->sql, $query->bindings, $query->time); }); } /** * Get latest number */ function getLatestNumber(string $tableName = 'incoming_letters', string $column = 'number'): int { /** @var null|object{max_number: string} $data */ $data = DB::table($tableName)->select(DB::raw("MAX(CAST(REGEXP_REPLACE({$column}, '[^0-9]', '') AS UNSIGNED)) AS max_number"))->first(); return $data ? intval($data->max_number) : 0; } /** * Written format of money in turkmen */ function moneyFormatInTurkmenLetter(int|float|string $money): string { return TurkmenNumberFormatter::format(floatval($money)); } /** * Send a sms */ function sendSMS(string|int $phone, string|int $message): mixed { $response = Http::retry( times: 3, sleepMilliseconds: 50, throw: false, when: function (Exception $exception, PendingRequest $request) { Log::channel('sms_api_error') ->error('Exception: ', [ 'message' => $exception->getMessage(), 'line' => $exception->getLine(), ]); return true; }) ->post('http://216.250.14.144:3000/api/data', [ 'phone' => '+993'.$phone, 'code' => $message, ]); return $response->body(); }