'Laravel Ldaprecord - display retrieved data from Active Directory in blade
When I retrieve data from Active Directory like:
$users = User::whereStartsWith('cn', $request->search)
->limit(3)
->get();
I retrieve an collection which looks like this:
LdapRecord\Models\Collection {#350 ▼
#items: array:3 [▼
0 => LdapRecord\Models\ActiveDirectory\User {#353 ▼
#passwordAttribute: "unicodepwd"
#passwordHashMethod: "encode"
#dates: array:7 [▶]
#defaultDates: array:3 [▶]
#sidKey: "objectsid"
+exists: true
+wasRecentlyCreated: false
+wasRecentlyRenamed: false
#dn: "CN=DOE John,DC=my,DC=domain"
#in: null
#connection: null
#guidKey: "objectguid"
#modifications: []
#original: array:95 [▶]
#attributes: array:95 [▶]
#casts: []
#appends: []
#dateFormat: null
#hidden: []
#visible: []
}
1 => LdapRecord\Models\ActiveDirectory\User {#354 ▼
#passwordAttribute: "unicodepwd"
#passwordHashMethod: "encode"
#dates: array:7 [▶]
#defaultDates: array:3 [▶]
#sidKey: "objectsid"
+exists: true
+wasRecentlyCreated: false
+wasRecentlyRenamed: false
#dn: "CN=SMITH Jan,DC=my,DC=domain"
#in: null
#connection: null
#guidKey: "objectguid"
#modifications: []
#original: array:94 [▶]
#attributes: array:94 [▶]
#casts: []
#appends: []
#dateFormat: null
#hidden: []
#visible: []
}
2 => LdapRecord\Models\ActiveDirectory\User {#357 ▼
#passwordAttribute: "unicodepwd"
#passwordHashMethod: "encode"
#dates: array:7 [▶]
#defaultDates: array:3 [▶]
#sidKey: "objectsid"
+exists: true
+wasRecentlyCreated: false
+wasRecentlyRenamed: false
#dn: "CN=LORD Coeh,DC=my,DC=domain"
#in: null
#connection: null
#guidKey: "objectguid"
#modifications: []
#original: array:66 [▶]
#attributes: array:66 [▶]
#casts: []
#appends: []
#dateFormat: null
#hidden: []
#visible: []
}
]
#escapeWhenCastingToString: false
}
Inside this collection, under protected property called #original(which is also an array), there are fields like sAMAccountName, dc, mail etc (there are different amount depends of user).
I can't display it in blade using foreach like:
@foreach ($users as $user)
<tr>
<td>{{ $user->cn }}</td>
<td>{{ $user->samaccountname }}</td>
<td>{{ $user->mail }}</td>
</tr>
@endforeach
Because I got an error:
htmlspecialchars() expects parameter 1 to be string, array given
How to print elements, which are sewn inside collection?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
