public function getTranslatedFieldName($fieldName, $locale) { if ($locale == '') { return $fieldName; } return translate_field_name($fieldName, $locale); }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { foreach (config('app.locales') as $locale) { $rules[translate_field_name('name', $locale)] = 'required'; } return $rules; }
public function updateWithRelations(array $attributes) { foreach (config('app.locales') as $locale) { $this->translate($locale)->text = $attributes[translate_field_name('text', $locale)]; } return $this; }
public function useInitialValue($subject, string $propertyName, string $locale = '') : string { $fieldName = $locale ? translate_field_name($propertyName, $locale) : $propertyName; $value = $locale ? $subject->translate($propertyName, $locale) : $subject->{$propertyName}; if ($value instanceof Carbon) { $value = $value->format('d/m/Y'); } return $this->getValueAttribute($fieldName, $value) ?? ''; }
public function rules() : array { $rules = ['publish_date' => 'date_format:d/m/Y']; foreach (config('app.locales') as $locale) { $rules[translate_field_name('name', $locale)] = 'required'; $rules[translate_field_name('text', $locale)] = 'required'; } return $rules; }
protected function updateTranslations() { foreach (config('app.locales') as $locale) { foreach ($this->model->translatedAttributes as $fieldName) { $translatedFieldName = translate_field_name($fieldName, $locale); if (!$this->request->has($translatedFieldName)) { continue; } $this->model->translate($locale)->{$fieldName} = $this->request->get($translatedFieldName); } } }
/** * @param array $attributes */ protected function updateTranslatedFields($attributes) { foreach (config('app.locales') as $locale) { foreach ($this->translatedAttributes as $fieldName) { $translatedFieldName = translate_field_name($fieldName, $locale); if (!isset($attributes[$translatedFieldName])) { continue; } $value = $attributes[$translatedFieldName]; $this->translate($locale)->{$fieldName} = $value; } } }
protected function fieldName(string $name, string $locale = '') : string { return $locale ? translate_field_name($name, $locale) : $name; }