Tuesday, May 23, 2017

How to insert id from both tables into pivot table using laravel query builder

I have three tables in database

  1. users
  2. locations
  3. location_user (columns: user_id, location_id)

I'm fetching records from locations table in multiple-drop-down field of user registration form. While filling form user has to select value from drop-down and then submit.

After submitting the form I want to insert data into users table. At the same time I also want to insert id from users table into user_id column of location_user and selected value of locations from drop-down of user registration form into location_id column of location_user table.

I know how to get this to work using eloquent but I as i mentioned in the question I want to know how to deal with this task using query builder of laravel.



via viraj

Advertisement