Какие типы связей есть в Eloquent?

Ответ
class User extends Model {
    public function phone(): HasOne { return $this->hasOne(Phone::class); }
    public function posts(): HasMany { return $this->hasMany(Post::class); }
    public function roles(): BelongsToMany { return $this->belongsToMany(Role::class); }
}

class Post extends Model {
    public function user(): BelongsTo { return $this->belongsTo(User::class); }
    public function tags(): MorphToMany { return $this->morphToMany(Tag::class, 'taggable'); }
}

class Country extends Model {
    public function posts(): HasManyThrough {
        return $this->hasManyThrough(Post::class, User::class);
    }
}

Типы: hasOne, hasMany, belongsTo, belongsToMany (M:N через pivot), hasManyThrough, morphOne/morphMany/morphToMany (полиморфные).

🧠Квиз 🏆Лидеры 🎯Собесед. 📖Вопросы 📚База зн.