public function relatedModel()
{
return $this->hasOne(RelatedModel::class);
}
code
Define a One-to-One Relationship in Laravel Eloquent
This Laravel Eloquent ORM code defines a one-to-one relationship between the current model and the 'RelatedModel' class. The hasOne method indicates that each instance of the current model has one related record in the 'RelatedModel' table. The comments provide explanations for each part of the code.
Eloquent ORM
Relationship
hasOne