5 Adldap2 requires [Composer](https://getcomposer.org/) for installation.
7 Once you have composer installed, run the following command in the root directory of your project:
10 composer require adldap2/adldap2
18 // Construct new Adldap instance.
19 $ad = new \Adldap\Adldap();
21 // Create a configuration array.
23 // The domain controllers option is an array of your LDAP hosts. You can
24 // use the either the host name or the IP address of your host.
25 'domain_controllers' => ['ACME-DC01.corp.acme.org', '192.168.1.1'],
27 // The base distinguished name of your domain.
28 'base_dn' => 'dc=corp,dc=acme,dc=org',
30 // The account to use for querying / modifying LDAP records. This
31 // does not need to be an actual admin account. This can also
32 // be a full distinguished name of the user account.
33 'admin_username' => 'admin@corp.acme.org',
34 'admin_password' => 'password',
37 // Add a connection provider to Adldap.
38 $ad->addProvider($config);
41 // If a successful connection is made to your server, the provider will be returned.
42 $provider = $ad->connect();
44 // Performing a query.
45 $results = $provider->search()->where('cn', '=', 'John Doe')->get();
48 $user = $provider->search()->find('jdoe');
50 // Creating a new LDAP entry. You can pass in attributes into the make methods.
51 $user = $provider->make()->user([
53 'title' => 'Accountant',
54 'description' => 'User Account',
57 // Setting a model's attribute.
58 $user->cn = 'John Doe';
60 // Saving the changes to your LDAP server.
64 } catch (\Adldap\Auth\BindException $e) {
66 // There was an issue binding / connecting to the server.