directorytree/ldaprecord
LDAPRecord is an LDAP directory and Active Directory ORM for Laravel and PHP. It provides fluent models, query builder, authentication and user sync, event-driven operations, and easy integration with Laravel apps for managing and searching directory entries.
Strengths:
User, Group), enabling familiar CRUD operations (find(), create(), update()) and relationships.where(), orWhere(), whereIn()) that maps to LDAP filters, abstracting low-level LDAP syntax (e.g., (objectClass=person)). Aligns with Laravel’s query builder patterns.applyScopesTo()), critical for multi-tenant SaaS or enterprise applications. Fixes for global scope query mutations (v4.0.6) ensure reliability.CanAuthenticate, getAuthIdentifier()), enabling LDAP-backed auth out-of-the-box (e.g., Auth::attempt(['username' => 'john', 'password' => 'secret'])).DirectoryFake for unit testing, reducing flaky test failures (e.g., mock LDAP responses without scope inconsistencies).Weaknesses:
(&(objectClass=user)(memberOf=CN=IT,OU=Groups))). Not a "black box" for non-LDAP experts.ldap_* functions, which may introduce latency for high-frequency operations (e.g., sub-millisecond requirements). Benchmark against raw LDAP for critical paths.remember()) for manual caching; no native LDAP query caching (e.g., ttl for frequent reads).Fit for Laravel Ecosystem:
CanAuthenticate). Works alongside Laravel’s authentication, caching, and testing tools.Laravel Compatibility:
config/ldap.php). Example:
'connections' => [
'ad' => [
'url' => 'ldap://ad.example.com',
'base_dn' => 'dc=example,dc=com',
'username' => 'cn=admin,dc=example,dc=com',
'password' => 'password',
'use_ssl' => true,
],
],
app()->make(User::class)). Supports polymorphic relationships (e.g., morphing models by object class).Migration Path:
ldap_connect(), ldap_search(), etc., with LdapRecord models and query builder. Example:
// Before (raw LDAP)
$ldap = ldap_connect('ldap://ad.example.com');
$result = ldap_search($ldap, 'ou=users,dc=example,dc=com', '(objectClass=user)');
$entries = ldap_get_entries($ldap, $result);
// After (LdapRecord)
$users = User::where('objectClass', 'user')->get();
adldap2, phpLDAPadmin, or custom LDAP wrappers by mapping their queries to LdapRecord’s syntax. Example:
// adldap2 → LdapRecord
$adldap->search()->users()->where()->equality('department', 'IT');
// becomes
User::where('department', 'IT')->get();
LdapRecord\Traits\Authenticatable). Example:
use LdapRecord\Auth\Authenticatable;
class User extends Model implements Authenticatable {
use \Laravel\Sanctum\HasApiTokens;
use \LdapRecord\Auth\Authenticatable;
}
Compatibility Risks:
protected $casts = ['binaryGuid' => 'binary']).Critical Risks:
where()->where()->orWhere()).ldap:// vs. ldaps://).start_tls).Moderate Risks:
morphTo() for dynamic object classes.ldap_extended_control).Mitigation Strategies:
DirectoryFake for unit tests and integration tests with real LDAP servers.Ldap::DEBUG_FILTER, Ldap::DEBUG_ERROR).LdapRecord\Exceptions\ConnectionException).Key Questions for the Team:
where()->orWhere()->where()) or global scopes? If so, validate with the latest fixes (v4.0.6+).LDAP_INVALID_CREDENTIALS) in your application?DirectoryFake, mock LDAP servers)?How can I help you explore Laravel packages today?