Code Snippets

use Illuminate\Support\Facades\Auth;
$name=Auth::user()->name;
dd($name);
use Illuminate\Support\Facades\Auth;
use LdapRecord\Models\ActiveDirectory\Group;
 
$user = Auth::user();
$group = Group::find('CN=IVRAdmin,CN=Users,DC=lab2,DC=purplepi,DC=ie');
 
if ($user->ldap->groups()->recursive()->exists($group)) {
	echo (($user->ldap->cn[0]) . " is a member of the group ") . $group -> cn[0];
}
else {
	echo (($user->ldap->cn[0]) . " is NOT a member of the group ") . $group -> cn[0];
}

For the above to work - you must have your User model configured as below - see here for more info.

// app/User.php
 
// ...
use LdapRecord\Laravel\Auth\HasLdapUser;
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
use LdapRecord\Laravel\Auth\LdapAuthenticatable;
 
 
class User extends Authenticatable implements LdapAuthenticatable
{
    use Notifiable, AuthenticatesWithLdap, SoftDeletes;
    use HasLdapUser;
 
    // ...
}

Reference

If you need more robust customization of the response returned when a user is authenticated, Laravel provides an empty authenticated(Request $request, $user) method that may be overwritten if desired:

use Illuminate\Http\Request;
 
/**
 * The user has been authenticated.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  mixed  $user
 * @return mixed
 */
protected function authenticated(Request $request, $user)
{
    return response([
        //
    ]);
}
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies