Complete the code to define a one-to-one relationship in the User model using hasOne.
public function profile() {
return $this->[1](Profile::class);
}The hasOne method defines a one-to-one relationship where the current model owns the related model.
Complete the code to define the inverse one-to-one relationship in the Profile model using belongsTo.
public function user() {
return $this->[1](User::class);
}The belongsTo method defines the inverse of a one-to-one or one-to-many relationship, pointing back to the owning model.
Fix the error in this User model relationship method to correctly define a one-to-one relation.
public function profile() {
return $this->[1](Profile::class)->withTimestamps();
}The hasOne method is correct for one-to-one ownership. The withTimestamps() method is not valid here and should be removed, but the blank focuses on the relationship method.
Fill both blanks to define a one-to-one relationship with a custom foreign key and local key.
public function passport() {
return $this->[1](Passport::class, '[2]', 'id');
}Use hasOne to define the relationship. The foreign key on the Passport model is usually user_id.
Fill all three blanks to define the inverse one-to-one relationship with custom keys.
public function user() {
return $this->[1](User::class, '[2]', '[3]');
}The belongsTo method defines the inverse relation. The foreign key on this model is user_id, and the owner's key is id.