Howto dynamic Or Where on same Attribute? #382
-
Hi everybody, I want to build a LDAP Query based on a dynamic number of input values (as an array?) as an OR of the same LDAP Attribute (lets say a uid). Examples: input=["UserID1","UserID2"]; input=["UserID1","UserID2","UserID3"]; As you can see, the number of input values is dynamic, so it is not possible to use queryBuilders "$query->orWhere()" methods (https://ldaprecord.com/docs/core/v2/searching/#or-wheres) as it is impossible to have a dynamic number of them in the code. I can't find a method like "whereIn", which could accept an array of values and then build an Or Filter of them like this: At the moment I just can use "$query->rawFilter" and build the filter on my own to achieve this, correct? Thx in advance |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @t0mcat1337, Would this work for you? use LdapRecord\Connection;
$conn = new Connection();
$query = $conn->query();
$input = ["UserID1","UserID2","UserID3"];
foreach ($input as $id) {
$query->orWhere('uid', '=', $id);
}
// "(|(uid=UserID1)(uid=UserID2)(uid=UserID3))"
echo $query->getUnescapedQuery(); |
Beta Was this translation helpful? Give feedback.
-
@stevebauman : |
Beta Was this translation helpful? Give feedback.
Hi @t0mcat1337,
Would this work for you?