Answer the question
In order to leave comments, you need to log in
How to arrange relationships with such a Laravel table?
There are three models:
event_id | topic_id | speaker_id
1 | 1 | 1
1 | 1 | 2
1 | 2 | 5
2 | 1 | 3
Answer the question
In order to leave comments, you need to log in
Add the event_id row to the topic table Add the topic_id row to the
speaker table Add the topic_id row to
the event model
public function topic()
{
return $this->hasMany(Topic::class, 'event_id', 'event_id');
}
public function event(): BelongsTo
{
return $this->belongsTo(Event::class, 'event_id', 'event_id');
}
public function speaker()
{
return $this->hasMany(Speaker::class, 'topic_id', 'topic_id');
}
public function topic(): BelongsTo
{
return $this->belongsTo(Topic::class, 'topic_id', 'topic_id');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question