You're browsing documentation for an old version.

View Current

Quickstart

Introduction

LdapRecord-Laravel requires the following:

Requirements
PHP >= 7.2
Laravel >= 5.6
PHP LDAP extension enabled
An LDAP server (Active Directory, OpenLDAP, FreeIPA etc.)

Install, Setup & Usage

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 on each option.

Step 4 - Use LdapRecord

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 config/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]);
    }
}

Step 5 - Setup Authentication

View the authentication quickstart guide if you require LDAP authentication in your application.

Generated on March 17, 2024
Edit on GitHub