Can't include it in a Laravel project running on App Platform of Digital Ocean. #160
Unanswered
AdelinGhanaem
asked this question in
Bugs
Replies: 1 comment
-
Yes. I have same issue. Deploying on Laravel Forge. Deployment script sequence
SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (Connection: mysql, ..... SOLUTION
My custom model overrides <?php
namespace App\Models;
use Illuminate\Database\QueryException;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Spatie\TranslationLoader\LanguageLine;
class Translation extends LanguageLine
{
protected $table = 'language_lines';
/**
* @return array<string, string>
*/
public static function getTranslationsForGroup(string $locale, string $group): array
{
return Cache::rememberForever(static::getCacheKey($group, $locale), function () use ($group, $locale) {
// Trying to load translations from Database, if no connection then return empty array.
try {
$dbResult = static::query()
->where('group', $group)
->get()
->reduce(function ($lines, self $languageLine) use ($group, $locale) {
$translation = $languageLine->getTranslation($locale);
if ($translation !== null && $group === '*') {
// Make a flat array when returning json translations
$lines[$languageLine->key] = $translation;
} elseif ($translation !== null && $group !== '*') {
// Make a nested array when returning normal translations
Arr::set($lines, $languageLine->key, $translation);
}
return $lines;
});
return $dbResult ?? [];
} catch (QueryException $e) {
//dump($e->getMessage());
return [];
}
});
}
} In free time i will create PR. Or maybe someone will suggest better solution. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When building a project with this dependency and then replacing the
Illuminate\Translation\TranslationServiceProvider::class,
with 'Spatie\TranslationLoader\TranslationServiceProvider::class,' the application deployment crashes saying it cannot get a Database connection. And it is failing during thephp artisan package:discovery --anis
command. it seems that package discovery requires a DB connection which is not provided during build time. Is it possible thatSpatie\TranslationLoader\TranslationServiceProvider::class
is trying to get a connection to db before env variables that contains DB params are available?Beta Was this translation helpful? Give feedback.
All reactions