Jul 9, 2022
8
Level 1
How to sortBy date with nested relation?
good day, I just want to ask how to sortBy date with relation, I tried what saw in here, but nothings happen. Can anyone help me. Thank you,, here is my controller,
$work_order = WorkOrder::where('status', 9)
->with('getWorker', 'getJobOrder', 'getScope', 'getJobType', 'getScopeDescription', 'operator')
->when($this->worker_id, function ($query) {
$query->whereHas('getWorker', function ($q) {
$q->where('assigned_worker_id', $this->worker_id);
})->get();
})
->when($this->work_type_id, function ($query) {
$query->where('job_type_id', $this->work_type_id);
})
->when($this->start_date && $this->end_date, function ($query) {
$query->whereHas('getWorker', function ($q) {
$q->where('start', '>=', $this->start_date)
->where('start', '<=', Carbon::parse($this->end_date)
->addHour(23)->addMinute(59)->addSecond(59));
})->get();
}, function ($query) {
$query->whereHas('getWorker', function ($q) {
$q->whereMonth('start', '=', Carbon::now());
});
})
->get();
Level 1
@MichalOravec this works for me thank you,,
$users = User::orderBy(Company::select('name') ->whereColumn('companies.id', 'users.company_id') )->get();
Please or to participate in this conversation.