Skip to content

Query for retrieving "not disabled" users in Active Directory #651

Answered by stevebauman
emiliosh asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @emiliosh,

If you'd like to use it, there is already a built-in query builder method to return only enabled users:

/**
* Adds a enabled filter to the current query.
*/
public function whereEnabled(): static
{
return $this->notFilter(
fn ($query) => $query->whereDisabled()
);
}

public function apply(Builder $query, Model $model): void
{
    $query->whereEnabled();
}

However, if you'd like to do this yourself, try:

$query->notFilter(
    fn ($query) => $query->rawFilter(
        (new AccountControl)->setAccountIsDisabled()->filter()
    )
);

Let me k…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@emiliosh
Comment options

Answer selected by emiliosh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants