Eloquent Relationships

hasOne, hasMany, belongsTo, and many-to-many

Eloquent relationships define how models connect to each other through foreign keys.

A User has one Profile. One-to-one relationship.

users
idname
1Alice
profiles
iduser_idbio
11Developer
hasOne
PHP
// User model
public function profile() {
    return $this->hasOne(Profile::class);
}

$user->profile->bio; // 'Developer'