lundi 22 juin 2020

How to get Attribute and its related values from dynamically generated fields in Laravel

I have attribute and its related attribute values dynamically generated on my view, user can fill and that attribute with values can be saved in table.

<input type="text" name="attribute_name[attr_1]" placeholder="Attribute Name" class="form-control" required="">

<input type="text" name="attribute_value[][attr_1]" placeholder="Attribute Value" class="form-control" required="">

<input type="text" name="attribute_value[][attr_1]" placeholder="Attribute Value" class="form-control" required="">

<input type="text" name="attribute_name[attr_2]" placeholder="Attribute Name" class="form-control" required="">

<input type="text" name="attribute_value[][attr_2]" placeholder="Attribute Value" class="form-control" required="">

<input type="text" name="attribute_value[][attr_2]" placeholder="Attribute Value" class="form-control" required="">

I'm passing here the random key to the attribute name and that same name is passed to attribute values array as a key so that when i get the data through post i can distinguish and relate attribute with there respective attribute values and save it in same row.

One thing to note is the fields are created dynamically and it is not created using loop, but it can be added by clicking on Add button.

now i' getting data using something like this :

 foreach($request->attribute_name as $attribute)
                 {
                    
                 }

but this i cannot get the attribute and its related values.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3hU8kOT
via IFTTT

Aucun commentaire:

Enregistrer un commentaire