Well, in fact, the best solution would be to add an additional column to the Card table - user_id, if you often get all the cards for the user.
Laravel Has-Many-Through , .
, Laravel , , .
, .
, :
public function decks()
{
return $this->hasManyThrough('Deck', 'Subject');
}
$deck_with_cards = $user->decks()->with("cards")->get();
$cards = [];
foreach($deck_with_cards AS $deck) {
foreach ($deck->cards as $c) {
$cards[] = $c->toArray();
}
}
$cards $user.