Skip to content

Commit c3d52af

Browse files
authored
Merge pull request #16024 from snipe/fixes/#15977
Fixed #15977 - Set order by on companies
2 parents 9564f7f + 9672a13 commit c3d52af

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

app/Http/Controllers/Api/DepartmentsController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function index(Request $request) : JsonResponse | array
7272
case 'manager':
7373
$departments->OrderManager($order);
7474
break;
75+
case 'company':
76+
$departments->OrderCompany($order);
77+
break;
7578
default:
7679
$departments->orderBy($sort, $order);
7780
break;

app/Models/Department.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,17 @@ public function scopeOrderManager($query, $order)
141141
{
142142
return $query->leftJoin('users as department_user', 'departments.manager_id', '=', 'department_user.id')->orderBy('department_user.first_name', $order)->orderBy('department_user.last_name', $order);
143143
}
144+
145+
/**
146+
* Query builder scope to order on company
147+
*
148+
* @param \Illuminate\Database\Query\Builder $query Query builder instance
149+
* @param text $order Order
150+
*
151+
* @return \Illuminate\Database\Query\Builder Modified query builder
152+
*/
153+
public function scopeOrderCompany($query, $order)
154+
{
155+
return $query->leftJoin('companies as company_sort', 'departments.company_id', '=', 'company_sort.id')->orderBy('company_sort.name', $order);
156+
}
144157
}

0 commit comments

Comments
 (0)