DirectoryTree / LdapRecord

A fully-featured LDAP framework.
https://ldaprecord.com
MIT License
502 stars 44 forks source link

LDAP_HOST only one server #622

Closed pincopallino2015 closed 1 year ago

pincopallino2015 commented 1 year ago

Hello, If I set two domain controllers in the LDAP_HOST variable I get this error message: Cannot assign array to property LdapRecord\Connection::$host of type string. If I declare the $host property in the Connection class as an array or nothing like the old 2.x version everything works fine

stevebauman commented 1 year ago

Hi @pincopallino2015, do you mean the LDAP_HOST environment variable?

If so, this is because the hosts value inside of the config is already wrapped inside of an array. You must reformat the ldap.php config file hosts value to the below structure:

https://github.com/DirectoryTree/LdapRecord-Laravel/blob/98e8c4e5f38a006f09f7f86ce290228881e043b1/config/ldap.php#L32

<?php

return [
    'connections' => [

        'default' => [
-            'hosts' => [env('LDAP_HOST', '127.0.0.1')],
+            'hosts' => explode(',', env('LDAP_HOST', '127.0.0.1')),
            // ...
        ],

    ],

    // ...
];

Then, inside your .env, you can comma separate your hosts to use multiple:

LDAP_HOST=127.0.0.1,127.0.0.2

The LDAP_HOST variable is named singularly (not LDAP_HOST(S)) to indicate this.

Let me know if that works for you 👍

pincopallino2015 commented 1 year ago

Thanks a lot @stevebauman, now it works. 👍

stevebauman commented 1 year ago

Excellent! Thanks for following up @pincopallino2015 👍