vendredi 3 juillet 2020

Eloquent model relationship for final table

I've the following tables

Cities (City model)


+----+-------+
| id | name  |
+----+-------+
|  1 | tokyo |
+----+-------+


events (Event model)

+----+--------------------+---------+
| id |       title        | city_id |
+----+--------------------+---------+
|  1 | Biggest event ever |       1 |
+----+--------------------+---------+


event_user_applications (EventUserApplication model)


+----+----------+---------+
| id | event_id | user_id |
+----+----------+---------+
|  1 |        1 |       1 |
+----+----------+---------+

How do I get the city on EventUserApplication model. I tried both of this in the EventUserApplication

    public function city()
    {
//        return $this->belongsTo('App\Model\City', 'city_id')->using('App\Model\Event', 'event_id');
//        return $this->hasOneThrough('App\Model\City', 'App\Model\Event', 'city_id', 'id');
    }

Can't get any of this to work. Already spent hours. Please help. Thank you in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire