Use old('attribute', $model->translattions['attribute']['key']) in form partial
joseantoniopino opened this issue · comments
I have the edit and create inputs shared in the same partial.
When I try to access the create view it gives me the following error:
Undefined array key "es" (View: /route/to/project/resources/views/admin/products/partials/basic-info.blade.php)
<input type="text" name="name_es" value="{{old('name_es', $product->translations['name']['es'])}}">
<input type="text" name="name_fr" value="{{old('name_fr', $product->translations['name']['fr'])}}">
In the controller I am passing a new Product()
to the create view to be able to make old('attribute', $product->attribute)
(when returning null the input remains empty)
In this case, as the translations come in an array, and the new Product()
has no translations yet, it complains that there is no ['es']
Is there a way to use old()
in shared partial together with translations?
Thanks in advance.
PD:
Obviously this can be done with
{{old ('name_es', $product->translations['name']['es'] ?? null)}}
But my question is more focused on knowing if there is a method in the package that allows to bring an object for example $product->translation->name->es
or similar.