Guntar Guntar - 2 months ago 24
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.


You can use join() as:

$properties = Property::join('companies', 'properties.company_id', '=', '')