I wish to orderBy (sortBy) two different nested relationship columns in laravel.
I have the following query which returns the data that i need
return Assignments::with('worker.person', 'order_job.order.company', 'worker.rel_phones', 'worker.rel_emails')
->where('assigned', true)
->whereNotIn('worker_id', DB::table('files')->select('worker_id')->where([
['file_master_type_id', 6],
['worker_id', '!=', 0],
])
->orWhere([
['file_master_type_id', 7],
['worker_id', '!=', 0],
])
->whereNotNull('worker_id'))
->get();
i would like to be able to order by the company_name column in the order_job.order.company relationship as well as at the same time order by the surname column in the worker.person relationship.
is this possible or would it have to be done using raw sql / joins?