Hi all
Started learning Laravel a couple of weeks ago and now starting to write my first application as really this is the best way to learn so forgive me if my attempts are naive.
What is the best way to create/update one of more tables as part as my user registration?
I have two tables, one called 'members' and the other 'profiles'. I want to store the users email address and password in the 'members' table and then their real name etc. in the 'profiles' table. I need the members id to be stored in the profiles table.
This is how I am doing it currently.
$memberinputs = $request->only('email', 'password');
$user = Members::create($memberinputs);
$member_id = $user->id;
This is storing the data as I wanted and then I am getting the ID for that stored record so I can use it in the 'profiles' table.
What I would like to do is add the $member_id into the form data so I create the record once. Problem is I don't know what is the best way to do this.
This is the way I am doing it and it is working but as you will see I have to interact with the database more than once which is not good :/
$profileinputs = $request->only('role_player', 'role_referee', 'role_coach', 'role_club', 'language');
$profile = Profile::create($profileinputs);
$profile_id = $profile->id;
$user = Profile::find($profile_id);
$user->member_id = $member_id;
$user->save();
As you can see I am creating the record to store the data captured from the form but then I am having to read the record back in to update it with the $member_id.
Is there a better, more efficient, way of doing this?