diff --git a/src/Creator.php b/src/Creator.php index 278a8e0..fc460b3 100644 --- a/src/Creator.php +++ b/src/Creator.php @@ -96,7 +96,7 @@ public function create(string $form_name, Model $model = null): HtmlAbstract throw new \InvalidArgumentException(sprintf('Model must be instance of "TranslatableModelAbstract", "%s" given', get_parent_class($model))); } $field = $this->factory->html('tabs')->setLabel($field_config['title']); - foreach (config('app.locales') as $locale) { + foreach (config('easy_form.config.locales') as $locale) { $fieldObject = $this->prepareField($field_config, $model, $locale); $field->addTab( $this->factory->html('tab')->setTitle($locale)->setId($field_config['name'] . '_' . $locale)->setContent($fieldObject) @@ -141,7 +141,7 @@ private function prepareField(array $field_data, Model $model = null, string $lo $field = $this->factory->autoMake($input_name, $field_data['type'], $field_data['title']); switch (true) { - case ($value = $this->getRequest()->old(array_key(Arr::dot($input_name)))) !== null: + case ($value = $this->getRequest()->old(arrayToDot($input_name))) !== null: break; case $model !== null: $value = null === $locale ? $model->getAttribute($field_data['name']) : $model->getLocalizedAttribute($locale, $field_data['name']); diff --git a/src/Factory.php b/src/Factory.php index 316d5cd..9fc0b6f 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -47,11 +47,11 @@ public function __construct(array $aliases = []) */ public function make(string $alias, string $type) { - if (!array_key_exists($alias, $this->aliases[$type])) { + if (!array_key_exists(strtolower($alias), $this->aliases[$type])) { throw new InvalidAliasException(sprintf('Alias "%s" for type "%s" not registered', $alias, $type)); } - $class = $this->aliases[$type][$alias]; + $class = $this->aliases[$type][strtolower($alias)]; return new $class($this); } diff --git a/src/Models/TranslatableModelAbstract.php b/src/Models/TranslatableModelAbstract.php index 508e768..cf07e03 100644 --- a/src/Models/TranslatableModelAbstract.php +++ b/src/Models/TranslatableModelAbstract.php @@ -71,7 +71,7 @@ public function saveTranslations(): void return; } $isUpdated = false; - foreach (config('app.locales') as $locale) { + foreach (config('easy_form.config.locales') as $locale) { $_data = []; foreach ($this->request_translations as $attr => $translations) { $_data[$attr] = $translations[$locale]; diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 1cb17a7..dbdede1 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -8,6 +8,7 @@ public function register() { $this->mergeConfigFrom($this->getAliasesConfigPath(), 'easy_form.aliases'); $this->mergeConfigFrom($this->getFormsConfigPath(), 'easy_form.forms'); + $this->mergeConfigFrom($this->getMainConfigPath(), 'easy_form.config'); $this->app->singleton(Creator::class, function () { $configResolver = $this->app->make('config'); @@ -25,11 +26,17 @@ public function boot() $this->publishes([ $this->getAliasesConfigPath() => config_path('easy_form/aliases.php'), + $this->getMainConfigPath() => config_path('easy_form/config.php'), $this->getFormsConfigPath() => config_path('easy_form/forms.php'), $this->getViewsPath() => resource_path('views/vendor/easy_form'), ]); } + private function getMainConfigPath() + { + return __DIR__ . '/resources/config/config.php'; + } + private function getAliasesConfigPath() { return __DIR__ . '/resources/config/aliases.php'; diff --git a/src/resources/config/config.php b/src/resources/config/config.php new file mode 100644 index 0000000..2bfd356 --- /dev/null +++ b/src/resources/config/config.php @@ -0,0 +1,7 @@ + [ + 'en' + ], +]; \ No newline at end of file