DirectoryTree / LdapRecord-Laravel

Multi-domain LDAP Authentication & Management for Laravel.
https://ldaprecord.com/docs/laravel/v3
MIT License
492 stars 51 forks source link

[Support] get OU name when sync/import to DB #559

Closed hans0801 closed 1 year ago

hans0801 commented 1 year ago

Environment:

Hi @stevebauman ,

Here with me again 👯‍♂️ Just want to ask, is it possible if I need to get the OU name of the users that I sync into my DB? Because when I saw on the AD Users attribute details, there is no OU Name for those users.

Thanks in advance

stevebauman commented 1 year ago

Hey @hans0801!

Yes you can get the OU name from a user by using the Distinguished Name builder:

$user = User::findOrFail('cn=John,ou=Users,dc=local,dc=com');

$parentDn = $user->newDn($user->getParentDn());

// "Users"
$name = $parnetDn->name();

// "ou"
$attribute = $parnetDn->head();
hans0801 commented 1 year ago

Hei @stevebauman , very magic. It's worked like a charm. Thank you so much

stevebauman commented 1 year ago

Excellent, glad to hear. Happy to help! 👍