Skip to content
Advertisement

How to save multiple inputs in laravel in mysql database?

I have a ticketing system in laravel and my problem is I have multiple input fields in my site which are title fname lasname and that came from the inputs of how many passengers are included. Now I have two tables which are booking and booking_details. I want to save the Contact Details and Mobile Number (which are shown below) to bookings table, and the other input fields like the Title First Name… in the booking_details table referencing the booking_id. I already finished setting the database and the relations of the two tables and now my problem is to save multiple names of the passengers in my booking_details table? That is my only problem. I tried different ways like using the array but I can’t solve it. Maybe the syntax or logic is wrong. Can someone tell me what to do? Thanks in advance.

My Form.

JavaScript

Controller

JavaScript

Route

JavaScript

booking_details table

JavaScript

bookings table

JavaScript

Advertisement

Answer

Your data is coming as array from the form. So loop over the array and insert values in each iteration. Sample Approach:

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