Skip to content

A free open source IT asset/license management system

Added searchableRelationAliases to user model

snipe3d043245957e
diff --git a/app/Models/User.php b/app/Models/User.php
index 379819f084..b4fff56ae8 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -195,6 +195,30 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
'name' => ['first_name', 'last_name'],
];
+ /**
+ * Maps filter/API keys to the actual Eloquent relation names used in
+ * $searchableRelations. The User model uses "userloc" as its location
+ * relation name (to avoid a collision with the framework's own "location"
+ * magic), but every consumer — UI and API alike — sends the key "location".
+ *
+ * @var array<string, string>
+ */
+ protected $searchableRelationAliases = [
+ 'location' => 'userloc',
+ ];
+
+ /**
+ * Narrow structured-filter relation columns for specific UI/API filter keys.
+ *
+ * The advanced-search "location" field represents the location name, so
+ * structured filters should target only userloc.name (not address/city/etc).
+ *
+ * @var array<string, list<string>>
+ */
+ protected $searchableRelationFilterColumns = [
+ 'location' => ['name'],
+ ];
+
/**
* This sets the name property on the user. It's not a real field in the database
* (since we use first_name and last_name), but the Laravel mailable method