ctrans('texts.phone_validation_error'), ]; } /** * @param string $attribute * @param mixed $value * @return bool */ public function passes($attribute, $value) { nlog("hitting twilio"); $sid = config('ninja.twilio_account_sid'); $token = config('ninja.twilio_auth_token'); if(!$sid) return true; $twilio = new \Twilio\Rest\Client($sid, $token); $country = auth()->user()->account?->companies()?->first()?->country(); if(!$country || strlen(auth()->user()->phone) < 2) return true; $countryCode = $country->iso_3166_2; nlog("hitting twilio try"); try{ $phone_number = $twilio->lookups->v1->phoneNumbers($value) ->fetch(["countryCode" => $countryCode]); $user = auth()->user(); $json = request()->json()->all(); $json['phone'] = $phone_number->phoneNumber; request()->json()->replace($json); $user->verified_phone_number = true; $user->save(); return true; } catch(\Exception $e) { return false; } } }