diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 3e35005011..0475b91b40 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -23,6 +23,7 @@ class Handler extends ExceptionHandler \Illuminate\Database\Eloquent\ModelNotFoundException::class, \Illuminate\Session\TokenMismatchException::class, \Illuminate\Validation\ValidationException::class, + \Intervention\Image\Exception\NotSupportedException::class, ]; /** diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 0e6ade1631..ee02f0e4ba 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -100,6 +100,9 @@ class UsersController extends Controller case 'department': $users = $users->OrderDepartment($order); break; + case 'company': + $users = $users->OrderCompany($order); + break; default: $allowed_columns = [ diff --git a/app/Models/User.php b/app/Models/User.php index 9155270f55..e72bb9ffac 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -549,4 +549,17 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo { return $query->leftJoin('departments as departments_users', 'users.department_id', '=', 'departments_users.id')->orderBy('departments_users.name', $order); } + + /** + * Query builder scope to order on company + * + * @param Illuminate\Database\Query\Builder $query Query builder instance + * @param text $order Order + * + * @return Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderCompany($query, $order) + { + return $query->leftJoin('companies as companies_user', 'users.company_id', '=', 'companies_user.id')->orderBy('companies_user.name', $order); + } }