Inserting data to main and pivot table at the same time

43 Views Asked by At

I have three tables users table, user_instrument table, and instruments table
The columns are as follows :
users table
-id
-name
-email
-password

user_instrument table
-id
-user_id
-instrument_id

instruments table
-id
-instrument_name

Now, in my registration form, along with the basic fields such as name, email, password. I also have an options of instruments that a user can choose.
Whenever a user registers, I want to simultaneously insert the users table with the name, email, password fields while the user_instrument table with user_id, instrument_id

I have read the eloquent relationship but all my attempts are just too confusing and doesn't make sense at all.
Please bare with me :(

0

There are 0 best solutions below