How would I insert rows to multiple tables when a user gets registered.
I have the basic Laravel user table. I also have a businesses table (id, business_name) and a usersbusinesses table (id, user_id, business_id)
First, I need to create (db insert) the user and get its generated id value.
Then, I need to create (db insert) the business and get its generated id value.
Finally, I need to create (db insert) a row in the usersbusinesses table using the values above (user_id and business_id)
I know I’m going to have to modify the app/Services/Registrar.php file, I just don’t know how to tackle this. Current code only inserts to users table:
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
public function create(array $data)
{
return User::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
Thanks Christian