I have two tables in MySQL where the first is called users and the second is called games. The structure of the table is as follows.
of users
- id (primary)
- Email
- password
- real_name
games
- id (primary)
- user_one_id (foreign)
- user_one_score
- user_two_id (foreign)
- user_two_score
My game table contains two external relationships for two users.
My question is how to make model relationships for this table structure? - According to the laravel documentation , I have to make a function inside the model and associate it with my relationships
eg
public function users() { $this->belongsTo('game'); }
however, I cannot find anything in the documentation telling me how to deal with two foreign keys. as in my table structure above.
Hope you can help me along the way here.
thanks
sql php mysql eloquent laravel
Rohwedder
source share