Guntar Guntar - 1 year ago 169
PHP Question

Laravel eloquent orderby two fields with the same name

I have two tables "Companies" and "Properties"
Have a relationship defined in Property class: return $this->belongsTo(Company::class);
I run this eloquent query to get all properties with companies


What i can't figure out is how do i orderBy first and then orderBy If I do this: orderBy('') I will get an error.
Any help would be highly appreciated.

Answer Source

You can use join() as:

$properties = Property::join('companies', 'properties.company_id', '=', '')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download