Fixed bug where sorting by company name in Users API did not work

Fixes [ch9200]
This commit is contained in:
snipe 2019-05-24 13:37:20 -07:00
parent b6d2392303
commit c5a23e8f5e
3 changed files with 17 additions and 0 deletions

View file

@ -23,6 +23,7 @@ class Handler extends ExceptionHandler
\Illuminate\Database\Eloquent\ModelNotFoundException::class, \Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class, \Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class, \Illuminate\Validation\ValidationException::class,
\Intervention\Image\Exception\NotSupportedException::class,
]; ];
/** /**

View file

@ -100,6 +100,9 @@ class UsersController extends Controller
case 'department': case 'department':
$users = $users->OrderDepartment($order); $users = $users->OrderDepartment($order);
break; break;
case 'company':
$users = $users->OrderCompany($order);
break;
default: default:
$allowed_columns = $allowed_columns =
[ [

View file

@ -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); 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);
}
} }