*/ protected $fillable = [ 'name', 'color', 'published', ]; /** * The translatable columns. * * @var list */ public $translatable = [ 'name', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'published' => 'boolean', ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted(): void { static::creating(function (self $model) { self::manageFields($model); }); static::updating(function (self $model) { self::manageFields($model); }); } // * METHODS /** * Manage model fields. * * @param self $model * @return void */ private static function manageFields(self $model): void { TranslationHelper::assertTranslationFieldIsUnique($model, $model->name, 'name'); self::validateFallbackTranslations($model); } /** * Assert fallback locale translation is present. * * @param self $model * @return void * @throws \Illuminate\Validation\ValidationException Translations missing. */ public static function validateFallbackTranslations(self $model): void { if (!$model->published) { return; } TranslationHelper::validateFallbackTranslations($model); } }