Quickstart

Step 1: Install LdapRecord-Laravel

Require LdapRecord-Laravel via composer:

composer require directorytree/ldaprecord-laravel

Step 2: Publish the LDAP configuration file

php artisan vendor:publish --provider="LdapRecord\Laravel\LdapServiceProvider"

Step 3: Configure your LDAP connection

Paste these environment variables into your .env file, and configure each option as necessary:

LDAP_LOGGING=true
LDAP_CONNECTION=default
LDAP_HOST=127.0.0.1
LDAP_USERNAME="cn=user,dc=local,dc=com"
LDAP_PASSWORD=secret
LDAP_PORT=389
LDAP_BASE_DN="dc=local,dc=com"
LDAP_TIMEOUT=5
LDAP_SSL=false
LDAP_TLS=false

View the core configuration documentation for more information.

Step 4: Usage

To begin, you may either use the built-in models that LdapRecord comes with, or you may create your own models that reference the connection you have created in your ldap.php file.

Call the below command to create a new LdapRecord model:

php artisan make:ldap-model User

Then use it in your application:

<?php

namespace App\Http\Controllers;

use App\Ldap\User;

class LdapUserController extends Controller
{
    public function index()
    {
        $users = User::get();

        return view('ldap.users.index', ['users' => $users]);
    }
}
Next Topic →

Overview