leftJoin in Eloquent?

Posted 11 months ago by [email protected]

Hello dear friends,

I'm beginner in Laravel, I'm using 5.5 version.

Is there a method leftJoin in Eloquent ORM? I know there is one on DB facade, but if I want to use Eloquent only is there a leftJoin method?

Let's suppose, as an simple example, I have a model CarBrand and another one CarModel. CarBrand have a relationship type hasMany with CarModel, and CarModel belongsTo CarBrand.

Suppose I want to find CarBrand's id's without CarModel corespondence. I found on stackOverflow, several responses like this:

 CarBrand::leftJoin('CarModelTableName', function($join) {
      $join->on('CarBrandTableName.id', '=', 'CarModelTableName.carBrandId');
    }) ->whereNull('CarModelTableName.carBrandId')->first();
     

I have checked and it does function as a left join :)

But in this case is ::leftJoin an Eloquent method or silently it goes to DB facade? I can't find any for leftJoin in Laravel 5 official docs other than DB facade. Any links would be appreciated.

Hope I was clear, Thank you for your attention.

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.