Adldap2 - Laravel allows easy configuration, access, management and authentication to LDAP connections utilizing the root Adldap2 Repository.
To use Adldap2-Laravel, your server must support:
- PHP 5.6 or greater
- PHP LDAP Extension
- An Active Directory Server
Note: OpenLDAP support is experimental, success may vary.
Insert Adldap2-Laravel into your composer.json
file:
"adldap2/adldap2-laravel": "3.0.*",
Or via command line:
composer require adldap2/adldap2-laravel
Then run composer update
.
Once finished, insert the service provider in your config/app.php
file:
Adldap\Laravel\AdldapServiceProvider::class,
Then insert the facade:
'Adldap' => Adldap\Laravel\Facades\Adldap::class
Publish the configuration file by running:
php artisan vendor:publish --tag="adldap"
Now you're all set!
You can perform all methods on Adldap through its facade like so:
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();
// Authenticating against your LDAP server.
if (Adldap::auth()->attempt($username, $password)) {
// Passed!
}
// 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',
]);
$user->save();
Or you can inject the Adldap interface into your controllers:
use Adldap\AdldapInterface;
class UserController extends Controller
{
/**
* @var Adldap
*/
protected $adldap;
/**
* Constructor.
*
* @param AdldapInterface $adldap
*/
public function __construct(AdldapInterface $adldap)
{
$this->adldap = $adldap;
}
/**
* Displays the all LDAP users.
*
* @return \Illuminate\View\View
*/
public function index()
{
$users = $this->adldap->search()->users()->get();
return view('users.index', compact('users'));
}
}
To see more usage in detail, please visit the Adldap2 Repository.