Hi all,
Im at a crossroad now where i must realize that im looking blind at some not-working code (10 days going) and that i need to seek the help from you guys. Im actually so desperate that im willing to pay for a fix.
What im trying to acomplish is creating an order form page where i can add product to an order on a client. I have all the basics working, and creating the order on a client is working fine - but now im stuck on the add products page. Here i have made a table with initially one row, which in the first field can lookup products from the database via api, and populate product name, price, discount as well as calculate total price, vat etc. I have even figured out how to dynamicly create more rows and still have calculations working.
The big (BIG) issue is that when i try to save to the database, and in my post-controller do a dd i only get the first row and not the 2, 3, 4,etc row. If i manually add the rows to the db and view the order page (which fetches if there are products added) and hit save, the dd shows the lines.
The second issue will come after the first is solved, as to how to save the multiple rows.
Now - as i said - im desperate - looking blind here - so a reward is up to the one who can help me get this working.
My view: https://gist.github.com/olebulow/9706459
My controller: https://gist.github.com/olebulow/9706462
My orderlines-script.js: https://gist.github.com/olebulow/9706445
My general-scripts.js: https://gist.github.com/olebulow/9706449
I really hope someone can help me? :)
saving to the database is easy, just make a for
loop
$input = Input::all();
for ($idx = 0; $idx < count(Input::get('item_id')); $idx++)
{
$product = new Product;
$product->name = $input['item_name'][$idx];
( ... )
$product->save();
}
above only works if you have Input::get('item_id') contains an array with nth item id's
@zenry -> that part actually works, but i cant get laravel to serialize the form so no matter how many rows - it will only save 1 row. Simply cant figure it out ;/
Now after changing my controller to this:
https://gist.github.com/olebulow/9730366
i get this output after saving but only the first row is stored in db.
{"item_id":["1","2","4","5"],"item_code":["00805X6","4851361","GH97-15107B","APN-616-0611"],"item_desc":["Lumia 820 glas\/touch","Lumia 820 lcd","Galaxy Note 3 Sk\u00e6rm (hvid)","iPhone 5 Batteri"],"item_qty":["1","1","1","1"],"item_price":["640.00","680.00","1520.00","320.00"],"item_discount":["0","0","0","0"],"item_total":["640.00","680.00","1520.00","320.00"]}
So it seems that the right data is passed to the controller but it will only save the first row. But why..
Because you're returning inside the loop, so after the first $product->save() it returns the response. You need to move the return outside of the loop.
tommulroy said:
Because you're returning inside the loop, so after the first $product->save() it returns the response. You need to move the return outside of the loop.
what he said ^
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community