Skip to content

A free open source IT asset/license management system

Added admihn scopes

snipe23c50ea9a55b
diff --git a/app/Models/User.php b/app/Models/User.php
index 5c539ad1c9..0abca08320 100755
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -561,6 +561,18 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
return false;
}
+ /**
+ * Get action logs history for this asset
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v1.0]
+ * @return \Illuminate\Database\Eloquent\Relations\Relation
+ */
+ public function adminuser()
+ {
+ return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ }
+
/**
* Check whether two-factor authorization is required and the user has activated it
* and enrolled a device
@@ -685,6 +697,23 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
return $query->leftJoin('departments as departments_users', 'users.department_id', '=', 'departments_users.id')->orderBy('departments_users.name', $order);
}
+ /**
+ * Query builder scope to order on admin user
+ *
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param string $order Order
+ *
+ * @return \Illuminate\Database\Query\Builder Modified query builder
+ */
+ public function scopeOrderAdmin($query, $order)
+ {
+ // Left join here, or it will only return results with parents
+ return $query->leftJoin('users as admin_user', 'users.created_by', '=', 'admin_user.id')
+ ->orderBy('admin_user.first_name', $order)
+ ->orderBy('admin_user.last_name', $order);
+ }
+
+
/**
* Query builder scope to order on company
*