Skip to main content
Fortify

JetStream Fortify check if the user belongs to a specific role or is active while logging in

By April 4, 2021October 5th, 2021No Comments

This guide is helpful.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// JetstreamServiceProvider.php

Fortify::authenticateUsing(function (Request $request) {
            $user = User::where('email', $request->email)->whereFileNumber($request->fileNumber)->userActive()->role('Debtor')->first();

            if ($user &&
                Hash::check($request->password, $user->password)) {

                $userLoginDetailObj = new UserLoginDetail();
                $userLoginDetailObj->loginDetails($user->id);

                return $user;
            }
        });