Laravel Ldaprecord - 在刀片中显示从 Active Directory 检索到的数据
当我从 Active Directory 检索数据时,如下所示:
$users = User::whereStartsWith('cn', $request->search)
->limit(3)
->get();
我检索一个如下所示的集合:
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
}
在该集合内,在名为 #original
(也是一个数组)的受保护属性下,有诸如 之类的字段sAMAccountName
、dc
、mail
等(具体数量取决于用户)。
我无法使用 foreach
在 Blade 中显示它,例如:
@foreach ($users as $user)
<tr>
<td>{{ $user->cn }}</td>
<td>{{ $user->samaccountname }}</td>
<td>{{ $user->mail }}</td>
</tr>
@endforeach
因为我收到错误:
htmlspecialchars() expects parameter 1 to be string, array given
如何打印在集合中缝制的元素?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其中一个属性是一个数组,必须先内爆为字符串,然后才能被 html 处理器
{{ }}
使用。以下代码检查属性是否为数组,然后执行 implode 函数,否则返回属性的原始值。
One of the properties are an array and must be imploded to a String before it can be used by the html processor
{{ }}
.The following code checks if the property is an array, then it performs the implode function, otherwise it returns the original value of property.