Skip to content
Advertisement

Laravel, store multiple variables from array into DB

Im not sure if the question title is correct but what I wanna do is clear in the example below I have 3 arrays and I want to store data in one table

the table structure is like this

table name: tour_transports

id

transport_id

transport_track

transport_note

arrays coming from blade

JavaScript

so as you see the ids are 1 and 5 so I wanna store two rows here

id = 1,transport_id = 1 , transport_track = from airport to the hotel , transport_note = be ready at 4:pm

id = 2,transport_id = 5, transport_track = from hotel to the beach , transport_note = bring ur swiming suite

I tried to do this but can’t get it correct

JavaScript

Advertisement

Answer

You can use this code to achieve your results:

JavaScript

Now $results contains the required data. However the better solution might be to configure your html form to send related data in single array entry, Like:

JavaScript

Which you can also use Javascript/php loops to generate the form inputs. Then you will receive form data in server side in well formed structure like:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement