Well first of all, I must say it is my personal opinion that this relation makes no sense. There is no reason the users table is connected to the platforms table directly. It should connect only through the games table, as I have described above.
Next, as far as I know, Laravel does not support this. So you are probably going to have to write every method yourself to Keep these data in Synchronization.
Still, if you want to continue with this method, I think this might work out for your case. But again this would simply simulate three 2-way pivot tables: game_user, platform_user and game_platform. These are all ManyToMany Relations.
A Many To Many Relation is declared like this:
return $this->belongsToMany('App\Model', 'foreign_key', 'local_key', 'table_name');
So for your case, the User Model is like this:
public function games() {
return $this->belongsToMany(Games::class, 'user_id', 'id', 'users_games_platforms');
}
public function platforms() {
return $this->belongsToMany(Platform::class, 'user_id', 'id', 'users_games_platforms');
}
The Game Model:
public function users() {
return $this->belongsToMany(User::class, 'game_id', 'id', 'users_games_platforms');
}
public function platforms() {
return $this->belongsToMany(Platform::class, 'game_id', 'id', 'users_games_platforms');
}
The Platform Model:
public function users() {
return $this->belongsToMany(User::class, 'platform_id', 'id', 'users_games_platforms');
}
public function games() {
return $this->belongsToMany(Game::class, 'platform_id', 'id', 'users_games_platforms');
}
So now, if the above works, you should be able to do the following:
-
$user = User::find($id)->with('platforms'); to get the Platforms of a User
-
$user = User::find($id)->with('games'); to get the Games of a User
-
$game = Game::find($id)->with('users'); to get the Users of a Game
-
$platform = Platform::find($id)->with('users'); to get the Users of a Platform
But again I seriously advise against going though with this method and follow the one I posted previously.