Отношения

Один-к-Одному
users
    id
    name
    
profiles
    id
    user_id
    title
class User extends Model
{
    public function profile()
    {
        return $this->hasOne(Profile::class);
    }
}
class Profile extends Model
{
    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
Один-ко-Многим
Многие через отношение

mechanic hasMany cars cars hasMany owners значит можно достать всех владельцев всех машин конкретного механика mechanic hasManyThrough(Owner::class,Car::class);

Многие-ко-Многим

Last updated