From 3a1fb615e7fadc2ca5cac165e3b33561464fcca5 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 13 Nov 2024 18:22:05 +0000 Subject: [PATCH] Added admin sort scope Signed-off-by: snipe --- app/Models/AssetModel.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.php index 6fdc39dd9a..02b5df40d1 100755 --- a/app/Models/AssetModel.php +++ b/app/Models/AssetModel.php @@ -329,4 +329,14 @@ class AssetModel extends SnipeModel { return $query->leftJoin('custom_fieldsets', 'models.fieldset_id', '=', 'custom_fieldsets.id')->orderBy('custom_fieldsets.name', $order); } + + /** + * Query builder scope to order on created_by name + * + */ + public function scopeOrderByCreatedByName($query, $order) + { + return $query->leftJoin('users as admin_sort', 'models.created_by', '=', 'admin_sort.id')->select('models.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } + }