lundi 24 juin 2019

How to get the data from an array in the controller, which is passed from the view

In the project I'm currently working on, there is a situation similar to a many-to-many relationship between a store and a product. A product can appear many stores while the stores will also have multiple products. Though the same product can have different prices in different stores.

Therefore a many-to-many relationship have been defined between both models. Store ID, Product IDs, prices of each product and a product's status in that particular will be saved to the intermediate table upon adding a new store.

So I need to pass the array of product IDs along with each one's price in that particular store (entered by the user upon creating the store) and the status of the product (entered by the user upon creating the store), from the view to the controller in order to pass them with attach().

I've managed to pass an array of key value pairs with the regarding data into a hidden filed (with use of JQuery) and pass them to the controller.

Now I want to know how to take apart that key-value pairs in the array in order to pass them properly through the attach method.

Also I feels like there must be an easy way of doing this other than writing a massive amount of jQuery, though I could't find any alternative. If there is any other way please let me know as well.

The array of data looks something like this;

[product_id_1 => [price => product_1_price, stat => product_1_stat], product_id_2 => [price => product_2_price, stat => product_2_stat], product_id_3 => [price => product_3_price, stat => product_3_stat]]

Any support provided will be appreciated.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2X864wX
via IFTTT

Aucun commentaire:

Enregistrer un commentaire