First question:
Why does Fluent
return an array
:
return DB::connection('mysql')->table('cards')
->where('setCode', '=', $setcode)
->get();
While Eloquent
returns an object
:
return Card::where('setCode', '=', $setcode)
->get();
The data itself looks exactly the same as far as I can tell.
Second question:
The following code is in Fluent
:
DB::table('auth.users_deck_overview as deckOverviewDB')
->leftJoin('auth.users_deck_cards as deckCardsDB', 'deckOverviewDB.deck_uid', '=', 'deckCardsDB.deck_uid')
->leftJoin('mtg_cards.cards as cardsDB', 'deckCardsDB.card_uid', '=', 'cardsDB.uid')
->select('cardsDB.name', 'deckCardsDB.card_quantity', 'cardsDB.manaCost', 'cardsDB.colors', 'cardsDB.cmc')
->where('deckOverviewDB.username', '=', $user->username)
->where('deckOverviewDB.deck_uid', '=', $deckUid)
->where('deckCardsDB.board', '=', 0)
->where('cardsDB.cmc', '!=', '')
->get();
How would I change the above to Eloquent
assuming the users_deck_overview
, users_deck_cards
, cards
Models are DeckOverview
, DeckCard
, and Card
respectively?