Hi,
You need a many to many relation between players and hands with dealt_cards as pivot table.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi everyone,
I am building a small project about poker but I am having some problems representing something with the relations:
A hand is played by many players while a player plays a hand. So I have two tables, players and hands. A hand belongs to many players while a player has many hands. But I am also trying to associate dealt cards to my players and my hand. So for the moment I have four tables:
players
id
pseudo
hands
id
cards
id
value
color
dealt_cards
id
hand_id
player_id
card_id
I looked at the manytomanythrough relations on Laravel's documentation but it doesn't seem to correspond to what I am looking for..
In the best way, I would like to access to dealt cards in this way:
$hand = Hand::first();
$player = $hand->players()->first();
$collection = getDealtCards($hand,$player);
Thank you very much for your help!
Please or to participate in this conversation.