- How do I set up multi-domain LDAP authentication in Laravel using this package?
- Configure multiple LDAP connections in your `config/ldap.php` file, then define separate `LdapUserProvider` instances for each domain. Use the `LdapGuard` trait to bind each guard to its respective LDAP connection. The package handles routing requests to the correct domain automatically.
- What’s the difference between full and incremental sync strategies in LdapImporter?
- Full syncs overwrite all records, while incremental syncs (using `lastModified` timestamps) only update changed entries. Incremental syncs are faster for large directories (e.g., 50K+ users) and reduce API load. Use the `--strategy` flag in `ldap:sync` to choose between them.
- Can I use this package with Laravel 10 and PHP 8.2+?
- Yes, this package fully supports Laravel 10 and PHP 8.2+. Version 4.0.0 dropped PHP 8.1 support, so ensure your environment meets these requirements. Check the [compatibility table](https://github.com/DirectoryTree/LdapRecord-Laravel#requirements) for exact versions.
- How do I migrate from raw LDAP filters to the new LdapQueryBuilder?
- Replace raw filters like `(&(uid=%s)(objectClass=person))` with the fluent `LdapQueryBuilder`. For example, use `$query->where('uid', $username)->where('objectClass', 'person')`. The package provides a migration guide in the [upgrading docs](https://github.com/DirectoryTree/LdapRecord-Laravel#migrating-from-v3-to-v4).
- Does this package support conflict resolution when syncing LDAP and database users?
- Yes, it offers three default strategies: LDAP wins (overwrites DB), DB wins (ignores LDAP changes), or custom merge logic. Configure this in your `LdapImporter` settings. For complex scenarios, extend the `ConflictResolver` interface to implement custom rules.
- How can I test LDAP interactions in CI/CD without hitting a real directory?
- Use the `DirectoryEmulator` to mock LDAP responses, including nested groups and custom schemas. Configure it in your `phpunit.xml` or tests with `$this->app->singleton(DirectoryEmulator::class, fn() => new DirectoryEmulator())`. The emulator supports all CRUD operations and query building.
- What’s the best way to handle LDAP downtime in production?
- Combine the package’s graceful degradation with Laravel Horizon for circuit breakers. Cache LDAP responses (e.g., with `cache()->remember`) and set a short TTL (e.g., 5 minutes). For critical auth, implement a fallback to database users via `LdapUserProvider::fallback()`.
- Can I trigger actions (e.g., Slack alerts) when LDAP syncs start or fail?
- Yes, use the expanded event system. Listen for `LdapSyncStarted`, `LdapSyncCompleted`, or `LdapSyncFailed` events in your `EventServiceProvider`. For example: `event(new LdapSyncFailed($sync));` will dispatch to listeners like Slack or logging services.
- How do I map custom LDAP attributes to Eloquent fields dynamically?
- Use the `AttributeMapper` class to define runtime transformations. For example, map `telephoneNumber` to `phone` with `$mapper->map('telephoneNumber', fn($value) => preg_replace('/[^0-9]/', '', $value))`. Configure this in your `LdapModel` boot method.
- Are there alternatives to this package for LDAP in Laravel, and how does it compare?
- Alternatives include `adldap2-laravel` (simpler but less feature-rich) and `phpLDAPadmin` (web-based, not Laravel-native). This package stands out for its Eloquent-like models, incremental syncs, and event-driven architecture. It’s ideal for complex multi-domain setups, while alternatives may suffice for basic auth.