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