validate([ 'username' => ['required', 'string', 'max:250', 'exists:users,username'], 'verification' => ['nullable', 'integer', 'digits:5'], 'password' => ['nullable', 'string', 'min:8', 'confirmed'], ]); if ($request->filled('verification')) { return $this->verify(); } $user = User::where('username', $request->username)->first(); // sendSMSVerification($user->phone); return response()->json([ 'step' => 1, 'message' => __('We send you a verification code to ') . '****' .substr($user->phone, 4) ]); } /** * Verify phone number */ public function verify(): JsonResponse { $verification = Verification::where('username', $request->username) ->where('code', $request->verification) ->first(); if (! $verification) { return response()->json([ 'errors' => [ 'verification' => [ __('Incorrect verification code'), ] ], 'message' => __('Incorrect verification code') ]); } return response()->json([ 'step' => 2, 'message' => __("Now you can set your password, but please make sure that you dont forget it") ]); } }