DirectoryTree / LdapRecord-Laravel

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

[Support] Request support to find image attribute in ldap users #643

Closed FrancescoD3V closed 6 months ago

FrancescoD3V commented 6 months ago

Hi, I need your help to search for the 'jpegPhoto' attributes of my ldap users.

Currently I can download the image of the user logged into my app like this:

$user = Auth::user(); if ($user ->ldap->hasAttribute('jpegPhoto')) { $user ->ldap->getAttribute('jpegPhoto') }

Now I would like to be able to find the same attribute by being able to specify the ID of other users, for example $user = User::find($id);

What I get, however, is the data of my model but $User is not an object of type LdapRecord and therefore I cannot use $user->ldap->getAttribute

Can you give me some suggestions?

Environment:

stevebauman commented 6 months ago

Hi @FrancescoD3V,

For non-logged in users, you can retrieve the LdapRecord model using their synchronized Object GUID like so:

use App\Models\User;
use LdapRecord\Models\ActiveDirectory\User as LdapUser;

$eloquent = User::find(1);

$ldap = LdapUser::findByGuid($eloquent->guid);

if ($ldap->hasAttribute('jpegPhoto')) {
    // ...
}

Let me know if this is what you're looking for 👍

FrancescoD3V commented 6 months ago

Thanks, you are great!

stevebauman commented 6 months ago

Excellent, thanks @FrancescoD3V! Glad I could be of assistance.