Answer the question
In order to leave comments, you need to log in
How to store a user profile in the database?
There is a service where you can register using your username and password.
After that, the user can go to his personal account and set / change the name / surname in the profile + there are still a couple of fields by type of mail, country of residence and other things.
How to store it in the database?
I think that here it is necessary to yuzat 2 tables. One with user id (primary key), login and password. And in another table to store the user profile (the same fields).
The second table has the fields id (profile number), userid (id of the user this profile is linked to), name, surname, age, email, and others.
I would like to understand how to correctly create 2 records when registering a user (one in the user table, the second in the profile table).
So far, we have reached the point that we first create a user, then we make a request to the database to pull out his id, then we create an empty profile in the profile table, indicating the newly registered user in the userid id field.
Answer the question
In order to leave comments, you need to log in
It makes absolutely no sense to fence related tables for a dozen fields. For optimization, we use directories for countries and types of mail
Two Tables users
and profiles
a One-to-One
Relationship the profile is always needed, you can immediately register it in eager loading
class User {
protected $with = [
'profile',
];
public function profile(){
return $this->hasOne(Profile::class);
}
}
$user = User::create([
'email' => $input['email'],
'password' => Hash::make($password),
]);
$user->profile()->create([
'company' => $input['company'],
'position' => $input['position'],
]);
$user->profile->company
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question