I'm fairly new with Laravel. I'm still trying to learn it. My question is:
I have 3 tables named
- games
- game_options
game_platforms
I have 3 Models for those tables
Game Model
class Game extends Eloquent { protected $table = 'games'; public function platforms() { return $this->hasManyThrough('GamePlatform','GameOptions','id','game_id'); } }
GamePlatform Model
class GamePlatform extends Eloquent { protected $table = 'game_platform'; }
GameOption Model
class GameOptions extends Eloquent { protected $table = 'game_options'; }
So when I do
$game = Game::find(1)->platforms;
It only shows,
{"id":1,"platform_id":20,"game_id":1}
{"id":1,"platform_id":21,"game_id":1}
{"id":1,"platform_id":22,"game_id":1}
{"id":1,"platform_id":23,"game_id":1}
{"id":1,"platform_id":24,"game_id":1}
But I need game name and platform names with those ID's. The thing is, I want to do this with eloquent only. I could go with "DB" or oldschool SQL but I want to learn if this way is possible or not.
Also I'm looking for better documentation/books for laravel. Most of what I read were only introduce laravel or far too advanced for me.
hasManyThrough
whenbelongsToMany
would fit here. I don't know much abouthasManyThrough
so you can certainly tell me if I'm wrong, but maybe try changing that. At least then calling$game->platforms()
will give you aCollection
ofGameOption
s notGamePlatform
s