@peterpan26 if you're using LDAP for authentication, after a successful LDAP bind, you can log the user in using Laravel's authentication system
public function login(Request $request)
{
$email = $request->input('email');
$emailExists = DB::table('user_roles')->where('email', $email)->exists();
if (!$emailExists) {
return back()->with('error', 'You are not authorized to login with this email');
}
// If authentication is successful, create or retrieve the user and log them in
$user = User::where('email', $email)->first();
Auth::login($user);
return redirect()->intended('dashboard'); // Redirect to the intended page
}
Now, in your Blade template, you can access the authenticated user's email like this
@if(Auth::check())
<p>Logged in as: {{ Auth::user()->email }}</p>
@endif
@php
$userRoles = Auth::user()->roles->pluck('role')->toArray();
@endphp
@if(in_array('Administrator', $userRoles))
<p>Welcome, Administrator!</p>
@endif