validate([ 'username' => ['required', 'string', 'max:250', 'exists:users,username'], 'verification' => ['nullable', 'integer', 'digits:5'], 'password' => ['bail', 'nullable', 'string', 'min:8', 'confirmed'], ]); if ($request->filled('verification')) { return $this->verify(); } $user = User::where('username', $request->username)->first(); // sendSMSVerification($user->phone); $phone_code = rand(10000, 99999); $verification = Verification::where(['username' => $user->phone])->first(); $verification ? $verification->update(['code' => $phone_code]) : Verification::create(['username' => $user->phone, 'code' => $phone_code]); 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") ]); } }