Pending:
Table Users
Table UserProfiles
Users has a relationship with UserProfiles
public function hasOneProfile(){
return $this->hasOne('App\UserProfile','user_id','id');
}
UserProfiles has a belongsTo relationship with Users
public function belongsToUser(){
return $this->belongsTo('User','user_id','id');
}
When a new $user = new Users();
is created
How to directly write the attributes of $user
so that when save()
is achieved, the UserProfile can be created directly?
For example:
Only specify one attribute for UserProfile sex=1
Then how can you directly create it as a new User and UserProfile together...
Create the user profile before saving. The user profile cannot be saved until it is created successfully.