Support the ongoing development of Laravel.io →
posted 10 years ago
Forms Jobs
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

@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 ;/

Last updated 2 years ago.
0

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..

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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 ^

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

olebulow olebulow Joined 31 Jan 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.