im creating a multilanguage app, and in it i have a table that stores the information of products in different languages.
My db Structure is:
Languages:
- id;
- name;
- iso;
ex: 1, english, en | 2, spanish, es
Products:
- id;
- category_id;
- online;
- price;
Products_Translations:
- id;
- product_id;
- name;
- description;
- language_id;
Busically based in this structure i cant manage the languages that exist on my app.
So basically in my view edit page i have something like this:
@foreach($languages as $language)
<h4></h4>
<div class="form-group">
<label for="category">Titlle</label>
<input type="text" class="form-control" required="" name="name_" id="name" placeholder="TÃtulo ">
</div>
<div class="form-group">
<label for="category">Description</label>
<textarea class="form-control" required name="description_" rows="5"></textarea>
</div>
<hr>
@endforeach
So after submmitting the data in my "$request->all()" i get something like:
array:7 [▼
"_token" => "8EVkeyHkAggV9sd2eEMUpclryDM1BB1Yh6J3Xs8R"
"name_en" => "Title EN"
"description_en" => "deacriao en"
"name_es" => "title PT"
"description_es" => "descriapo ES"
]
How i would validate dynamic content in my controller?
I know that the only dynamic content i have of inputs fields would be the 'name' and 'description' on products_translated' table, so maybe i would first get all my languages and loop and build these fields based on what i would receive on the request, but how i would implement it in the $request data?
$languages = Language::all();
$this->validate($request, array(
'title_' => 'required|min:2'
...
));
via Pedro