directorytree/ldaprecord
LDAPRecord is a fully featured LDAP and Active Directory ORM for Laravel and PHP. It provides Eloquent-style models, querying, authentication and user sync, and tools for working with directory entries, connections, and schema—built for reliable, modern LDAP apps.
where, orWhere, andFilter, memberOf), pagination, and chunking, critical for large-scale LDAP operations.ext-ldap, ext-json, and ext-iconv, which are standard for LDAP operations but must be verified in the target environment.simple-cache) for frequent queries.ldaprecord to reuse connections.chunk() for bulk operations to avoid memory issues.Ldap::DEBUG_*) to aid troubleshooting.LdapRecord’s features (e.g., CanAuthenticate, memberOf) are fully leveraged.allow_insecure_password_changes (v3.6.0+), but this may conflict with compliance needs.Ldap::DEBUG_*).CanAuthenticate trait). Works alongside Eloquent, Queues, and Cache.getAuthIdentifier() and Failed events, enabling LDAP-backed user authentication with minimal boilerplate.DirectoryFake) for unit/integration tests, reducing reliance on live LDAP servers.Failed for authentication failures) for reactive workflows (e.g., logging, notifications).adldap2, custom scripts) to identify replacement candidates.User, Group) using morphClass().config/ldap.php).'connections' => [
'ad' => [
'host' => env('LDAP_HOST'),
'protocol' => 'ldaps', // Custom protocol support (v3.7.0+)
'base_dn' => env('LDAP_BASE_DN'),
'username' => env('LDAP_USERNAME'),
'password' => env('LDAP_PASSWORD'),
'allow_insecure_password_changes' => env('LDAP_ALLOW_INSECURE', false),
],
],
LdapRecord\Models\Model for custom LDAP models:
use DirectoryTree\LdapRecord\Models\Model;
class User extends Model
{
protected $dn = 'ou=users,dc=example,dc=com';
protected $attributes = ['uid', 'mail', 'memberOf'];
protected $casts = ['isActive' => 'boolean'];
}
class DirectoryEntry extends Model
{
public function morphClass(): string
{
return $this->getObjectClass() === 'group' ? Group::class : User::class;
}
}
php artisan vendor:publish --provider="DirectoryTree\LdapRecord\Laravel\LdapRecordServiceProvider"
// Find users in a group
$users = User::whereMemberOf('CN=Admins,DC=example,DC=com')->get();
// Complex filtering
$query = User::where(function ($q) {
$q->where('department', 'IT')
->orWhere('title', 'Developer');
})->get();
use DirectoryTree\LdapRecord\Laravel\Auth\CanAuthenticate;
class User extends Model implements CanAuthenticate
{
public function getAuthIdentifier(): string
{
return $this->uid;
}
}
DirectoryFake for isolated tests:
use DirectoryTree\LdapRecord\Testing\DirectoryFake;
public function test_user_creation()
{
DirectoryFake::fake();
$user = User::create(['uid' => 'john', 'mail' => 'john@example.com']);
$this->assertEquals('john', $user->uid);
DirectoryFake::assertCreated('uid=john,ou=users,dc=example,dc=com');
}
How can I help you explore Laravel packages today?