cabeeb
6 months ago
571
1
Laravel

Load Relationship Pivot OR Relationship from Route

Posted 6 months ago by cabeeb

Hey all, sorry if this has been asked before, but I'm not sure exactly what to search for.

So, I have an api route /games/{game}/players/{player} to view a player's data for a game. I need to access the relationship's pivot data for certain actions, as well as to make sure that the player is actually in the game. Is there a way to automatically have Laravel load the relationship in a nested route like that? And if not, is there a better way to load the pivot data other than reloading the whole relationship with $player = $game->find($player->id)

Thanks!

Please sign in or create an account to participate in this conversation.