shimana's avatar

CustomLoginRequest for Fortify

I want to use a mobile number and password for login in fortify . I have created a CustomLoginRequest for set rules().

in FortifyServiceProvider

        Fortify::authenticateUsing(function (CustomLoginRequest $request) {

            $user = User::where('mobile', $request->mobile)->first();

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

            return null;
        });

I received an error.

‍‍‍App\Providers\FortifyServiceProvider::App\Providers\{closure}(): Argument #1 ($request) must be of type App\Http\Requests\CustomLoginRequest, Laravel\Fortify\Http\Requests\LoginRequest given

I changed the code by adding app(CustomLoginRequest::class); as follows, and the issue was resolved.

        Fortify::authenticateUsing(function (Request $request) {

         app(CustomLoginRequest::class);

            $user = User::where('mobile', $request->mobile)->first();

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

            return null;
        });

Is what I did standard and correct, or is there another solution

0 likes
0 replies

Please or to participate in this conversation.