- How do I set up LdapRecord for Laravel authentication like Auth::attempt()?
- Use the `CanAuthenticate` trait in your LDAP model (e.g., `User::class`). Configure the `auth` driver in `config/auth.php` to point to your LDAP connection, then call `Auth::guard('ldap')->attempt()`. The package handles binding and credential validation automatically.
- Does LdapRecord support Laravel 13 and PHP 8.4?
- Yes, LdapRecord v4.x is fully compatible with Laravel 11–13 and PHP 8.1–8.4. Check the [release notes](https://github.com/DirectoryTree/LdapRecord/releases) for version-specific features like `insertAndGetDn` in v4.0.0+.
- Can I query nested LDAP groups or use complex filters (AND/OR) like Eloquent?
- Absolutely. Use `whereMemberOf()` for groups and chain `orFilter()`/`andFilter()` for complex queries. Example: `User::where('department', 'IT')->orFilter('title', 'Admin')`. Nested filters were fixed in v4.0.1.
- How do I test LDAP operations without hitting a real directory server?
- Use `DirectoryFake`, a built-in testing tool. Mock connections in your tests with `DirectoryFake::fake()` and assertions like `DirectoryFake::assertBound()`. It simulates LDAP responses for unit/integration tests.
- What’s the best way to handle multi-tenancy with separate LDAP base DNs?
- Bind tenant-specific configurations to Laravel’s service container. Use `config(['ldap.connections.tenant1' => [...]])` per request or middleware. The package supports dynamic base DNs via `{base}` syntax in queries.
- How do I debug LDAP connection issues or slow queries?
- Enable debug constants like `LDAP_DEBUG_FILTER` or `LDAP_DEBUG_PACKETS` in your `.env`. For performance, use `chunk()` for large datasets or cache frequent queries with Laravel’s cache. Monitor TLS errors with `ldap_start_tls()`.
- Does LdapRecord work with Active Directory (AD) or only OpenLDAP?
- It supports both AD and OpenLDAP out of the box. AD-specific features like `objectSid` or `binaryGUID` require custom `AttributeCast` classes. Tested with AD 2016+ and OpenLDAP 2.4+. Schema flexibility is high but may need casting for non-standard fields.
- Can I sync users between Laravel and LDAP bidirectionally?
- Yes. Use Laravel’s `saved`/`deleted` events to trigger LDAP updates. Example: `User::saved(function ($user) { $user->ldapRecord()->save(); })`. For bulk syncs, leverage `chunk()` to avoid memory issues.
- What are the alternatives to LapRecord for LDAP in Laravel?
- Alternatives include `adldap2/adldap2-laravel` (simpler but less feature-rich) or `phpLDAPadmin` (web-based). LdapRecord stands out for its Eloquent-like API, Laravel integration (events, caching), and support for complex queries. Choose it for deep LDAP + Laravel synergy.
- How do I handle custom LDAP attributes (e.g., binary data like `objectSid`)?
- Extend `AttributeCast` in your model. Example: `protected $casts = ['objectSid' => 'binaryGUID'];`. For unsupported types, create a custom cast class implementing `AttributeCastInterface`. Check the [docs](https://github.com/DirectoryTree/LdapRecord#attribute-casting) for examples.