diff --git a/src/LanguageLine.php b/src/LanguageLine.php index 645222b..e790de5 100644 --- a/src/LanguageLine.php +++ b/src/LanguageLine.php @@ -37,6 +37,16 @@ public static function boot(): void public static function getTranslationsForGroup(string $locale, string $group): array { + // When the app uses laravel-sail the package breaks every artisan command ran outside sail context. + // That's beacuse artisan starts an app and registers all service providers, but the database is unavailable + // beacause the hostname (e.g. mysql) is unresolvable. + try { + DB::connection()->getPdo(); + } catch (PDOException $exception) { + Log::error('laravel-translation-loader: Could not connect to the database, falling back to file translations'); + return []; + } + return Cache::rememberForever(static::getCacheKey($group, $locale), function () use ($group, $locale) { return static::query() ->where('group', $group)