mardi 2 juillet 2019

Relation between two models with intermediate table

I have spent hours on trying and failing, reading documentation and trying to translate the documentation to a challenge I am facing in Laravel.

The worst part is, I don't think the issue is that hard to solve, but somehow my head won't work properly.

The Laravel app I am working is a Tour de France Fantasy Manager. I have Rider and Stage models, and I have an intermediate RiderStageStatus model where I will store information about whether a rider is joining the stage. I want to implement stage results as well, so I guess the issue will turn up again for that later on.

However, my database looks like this:

riders
- id
- name
- ...

stages
- id
- departure
- arrival
- ...

statuses
- id
- name
- ...

rider_stage_statuses
- id
- rider_id
- stage_id
- status_id

So I should be able to get riders and their status for a certain stage Stage::find(1)->riders and also get statuses for each stage of a rider Rider::find(1)->stages.

But I cannot make the right relations in the models. What am I doing wrong?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2XhnUZt
via IFTTT

Aucun commentaire:

Enregistrer un commentaire