diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php index 52b8051ddc..561e13c9cd 100644 --- a/app/Http/Controllers/Api/ComponentsController.php +++ b/app/Http/Controllers/Api/ComponentsController.php @@ -98,6 +98,9 @@ class ComponentsController extends Controller case 'supplier': $components = $components->OrderSupplier($order); break; + case 'created_by': + $components = $components->OrderByCreatedBy($order); + break; default: $components = $components->orderBy($column_sort, $order); break; diff --git a/app/Models/Component.php b/app/Models/Component.php index 1ff233ed3c..7bba37ac12 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -310,4 +310,9 @@ class Component extends SnipeModel { return $query->leftJoin('suppliers', 'components.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order); } + + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as admin_sort', 'components.created_by', '=', 'admin_sort.id')->select('components.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } }