Laravel Ldaprecord - 在刀片中显示从 Active Directory 检索到的数据

问题描述 投票:0回答:1

当我从 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
在刀片中显示它,例如:

@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

如何打印集合中缝制的元素?

php laravel active-directory ldap
1个回答
0
投票
@foreach ($users as $user)
  <tr>
      <td>{{ implode($user->cn) }}</td>
      <td>{{ implode($user->samaccountname) }}</td>
      <td>{{ implode($user->mail) }}</td>
  </tr>
@endforeach
© www.soinside.com 2019 - 2024. All rights reserved.