RoyceDatabase - Laravel version 1.0.67
Requirements
Version 1.0.7, (*1)
To use Adldap2-Laravel, your application and server must meet the following requirements:, (*2)
- Laravel 5.*
- PHP 7.0 or greater
- PHP LDAP extension enabled
- An LDAP Server
Index
Installation
Run the following command in the root of your project:, (*3)
composer require adldap2/adldap2-laravel
Note: If you are using laravel 5.5 or higher you can skip the service provider
and facade registration and continue with publishing the configuration file., (*4)
Once finished, insert the service provider in your config/app.php
file:, (*5)
Adldap\Laravel\AdldapServiceProvider::class,
Then insert the facade:, (*6)
'Adldap' => Adldap\Laravel\Facades\Adldap::class
Publish the configuration file by running:, (*7)
php artisan vendor:publish --tag="adldap"
Now you're all set!, (*8)
Usage
First, configure your LDAP connection in the config/adldap.php
file., (*9)
Then, you can perform methods on your default connection through the Adldap
facade like so:, (*10)
use Adldap\Laravel\Facades\Adldap;
// Finding a user:
$user = Adldap::search()->users()->find('john doe');
// Searching for a user:
$search = Adldap::search()->where('cn', '=', 'John Doe')->get();
// Running an operation under a different connection:
$users = Adldap::getProvider('other-connection')->search()->users()->get();
// Creating a user:
$user = Adldap::make()->user([
'cn' => 'John Doe',
]);
// Saving a user:
$user->save();
If you do not specify an alternate connection using getProvider()
, your
default
connection will be utilized for all methods., (*11)
Upon performing operations without specifying a connection, your default
connection will be connected to and bound automatically
using your configured username and password., (*12)
If you would prefer, you can also inject the Adldap interface into your controllers,
which gives you access to all of your LDAP connections and resources as the facade., (*13)
use Adldap\AdldapInterface;
class UserController extends Controller
{
/**
* @var Adldap
*/
protected $ldap;
/**
* Constructor.
*
* @param AdldapInterface $adldap
*/
public function __construct(AdldapInterface $ldap)
{
$this->ldap = $ldap;
}
/**
* Displays the all LDAP users.
*
* @return \Illuminate\View\View
*/
public function index()
{
$users = $this->ldap->search()->users()->get();
return view('users.index', compact('users'));
}
/**
* Displays the specified LDAP user.
*
* @return \Illuminate\View\View
*/
public function show($id)
{
$user = $this->ldap->search()->findByGuid($id);
return view('users.show', compact('user'));
}
}
To see more usage in detail, please visit the Adldap2 repository., (*14)