ctrans('texts.phone_validation_error'), ]; } /** * @param string $attribute * @param mixed $value * @return bool */ public function passes($attribute, $value) { $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; try{ $phone_number = $twilio->lookups->v1->phoneNumbers($value) ->fetch(["countryCode" => $countryCode]); $user = auth()->user(); request()->merge([ 'phone' => $phone_number->phoneNumber ]); $user->verified_phone_number = true; $user->save(); return true; } catch(\Exception $e) { return false; } } }