Available Model Query Methods (API)

Important: The model query builder extends the base query builder.

All of its methods are available on model queries.

Method Listing

appliedScopes

Get an array of the global scopes that were applied to the model query:

$scopes = User::query()->appliedScopes();

findByAnr

Find the first matching model by ambiguous naming resolution:

Important: If your LDAP server does not support ANR, an equivalent filter will be generated automatically.

use LdapRecord\Models\ActiveDirectory\User;

if ($user = User::findByAnr('John Doe')) {
    // Found user!
} else {
    // Not found.
}

findByAnrOrFail

Find the first matching model by ambiguous naming resolution or fail:

Important: If your LDAP server does not support ANR, an equivalent filter will be generated automatically.

use LdapRecord\Models\ActiveDirectory\User;

try {
    $user = User::findByAnrOrFail('John Doe');
} catch (\LdapRecord\Models\ModelNotFoundException $ex) {
    // Not found.
}

findByGuid

Find a model by its string GUID:

use LdapRecord\Models\ActiveDirectory\User;

$guid = 'f53c7b48-e8d1-425f-a23a-d1b98d7abfe8';

if ($user = User::findByGuid($guid)) {
    // Found user!
} else {
    // Not found.
}

findByGuidOrFail

Find a model by its string GUID or fail:

use LdapRecord\Models\ActiveDirectory\User;

$guid = 'f53c7b48-e8d1-425f-a23a-d1b98d7abfe8';

try {
    $user = User::findByGuidOrFail($guid);
} catch (\LdapRecord\Models\ModelNotFoundException $ex) {
    // Not found.
}

findManyByAnr

Find multiple models using ambiguous naming resolution or fail:.

use LdapRecord\Models\ActiveDirectory\User;

$users = User::findManyByAnr(['Jane', 'John', 'Jack', 'Josh']);

removedScopes

Get an array of global scopes that were removed from the model query:

use LdapRecord\Models\ActiveDirectory\User;

$scopes = User::query()->withoutGlobalScope(
    OnlyAccountants::class
)->removedScopes();

withGlobalScope

Apply a new global scope on the model query:

use LdapRecord\Models\ActiveDirectory\User;

// Using a closure...
$users = User::withGlobalScope('accountants', function ($query) {
    // ...
})->get();

// Using a scope class...
$users = User::withGlobalScope(
    Accountants::class, new Accountants
)->get();

withoutGlobalScope

Query a model without a registered global scope:

use LdapRecord\Models\ActiveDirectory\User;

$users = User::withoutGlobalScope(Accountants::class)->get();

withoutGlobalScopes

Query a model without all registered global scopes:

use LdapRecord\Models\ActiveDirectory\User;

$users = User::withoutGlobalScopes()->get();
Generated on November 8, 2024
Edit on GitHub