From be98abb0d004cd53acd64be4aabaf243845bba85 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 22 Sep 2025 13:09:13 +0200 Subject: [PATCH] fix: :bug: validate translations when there is config associated to dynamic page --- app/Models/DynamicPage.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Models/DynamicPage.php b/app/Models/DynamicPage.php index 9f8fda89..fb3cb457 100644 --- a/app/Models/DynamicPage.php +++ b/app/Models/DynamicPage.php @@ -123,22 +123,24 @@ class DynamicPage extends Model return; } - $locales = collect(config('app.locales')); - $modelLocales = collect(array_keys($model->config->getTranslations('config'))); - $allowedLocales = $modelLocales->intersect($locales); + if ($model->config) { + $modelLocales = collect(array_keys($model->config->getTranslations('config'))); + $locales = collect(config('app.locales')); + $allowedLocales = $modelLocales->intersect($locales); - $missingLocales = $allowedLocales->reject( - fn($locale) => $model->hasTranslation('content', $locale) - ); + $missingLocales = $allowedLocales->reject( + fn($locale) => $model->hasTranslation('content', $locale) + ); - if ($missingLocales->isNotEmpty()) { - throw ValidationException::withMessages([ - 'content' => trans_choice( - 'back.missing_translations', - $missingLocales->count() > 2 ? \INF : 1, - ['locales' => Str::upper($missingLocales->implode(', '))] - ), - ]); + if ($missingLocales->isNotEmpty()) { + throw ValidationException::withMessages([ + 'content' => trans_choice( + 'back.missing_translations', + $missingLocales->count() > 2 ? \INF : 1, + ['locales' => Str::upper($missingLocales->implode(', '))] + ), + ]); + } } }