2

I have the following mysql query

select * from operatories o
left join apts ap on o.location = ap.Location and o.operatory = ap.Operatory;

I also have two models

class Operatories extends Model
{
    public function operatories()
    {
        return $this->hasMany('App\Models\Appointment', 'Location', 'location');
    }
}

Appointments:

class Appointment extends Model
{
    public function operatories()
    {
        return $this->belongsTo('App\Models\Operatories', 'operatory', 'Operatory');
    }
}

In my controller I am trying to write the mysql query,

this is what I have so far

$arrOperators   =   Operatories::leftJoin('appointment', function ($join) {
    $join->on('appointments.location','=','operatories.location');
})

does anyone know how to write multiple on clause?

  • 1
    Not something I know about, so perhaps a dupe of https://stackoverflow.com/questions/16848987/a-join-with-additional-conditions-using-query-builder-or-eloquent, but have a check first. – Nigel Ren Oct 11 '20 at 13:55
  • Did you check this other answer? https://stackoverflow.com/a/16849231/7117697 – Kenny Horna Oct 11 '20 at 15:07

0 Answers0