Laravel Fluent vs Eloquent Laravel Fluent vs Eloquent laravel laravel

Laravel Fluent vs Eloquent


First QuestionFluent is a query builder and Eloquent is an ORM. Eloquent is built upon Fluent.

Second QuestionThe short answer is you wouldn't. An ORM isn't really suited to do things this way. This is a square peg/round hole situation.

Laravel also applies convention over configuration. In your case this means that you'd probably be better off trying to restructure your database to match Eloquent's convention rather then configure Eloquent to match your database schema.

An oversimplified view of the ORM structure may look like this.

DeckOverviewhasMany DeckCardDeckCardbelongsToMany CardbelongsTo DeckOverviewCard belongsToMany DeckCard

The best way to pull all that data is through eager loading.

$deckOverview = DeckOverview::with('deckCards.cards')->first();

This is where the ORM really doesn't line up with your approach. An ORM is built to have an object that represents a record in the table. Here we have a DeckOverview that has a bunch of DeckCards. They would be accessed like so.

$deckCard = $deckOverview->deckCards->first();

Or maybe this...

foreach ($deckOverview->deckCards as $deckCard) {    foreach ($deckCard->cards as $card)    {        // do something with each card in the deck    }}

You can limit the results pulled through eager loading. This would only load DeckCards where the board was 0.

$deckOverviews = DeckOverview::with(array('deckCards' => function ($query) {    // Equals comparison operator can be assumed    $query->where('board', 0);})->get()

You can use has to apply constraints based on relationships. This would only load DeckOverviews that had DeckCards where the board was 0.

$deckOverviews = DeckOverview::has(array('deckCards' => function ($query){    $query->where('board', 0);});

There is a lot to take in here. It will require a major shift in how you plan and build your application.