countries = array_merge($this->countries, $countries); return $this; } /** * Set the country input field. * * @param string $name * @return $this */ public function countryField($name) { $this->countryField = $name; return $this; } /** * Set the phone types. * * @param int|string|array $type * @return $this */ public function type($type) { $types = is_array($type) ? $type : func_get_args(); $this->types = array_merge($this->types, $types); return $this; } /** * Shortcut method for mobile type restriction. * * @return $this */ public function mobile() { $this->type(PhoneNumberType::MOBILE); return $this; } /** * Shortcut method for fixed line type restriction. * * @return $this */ public function fixedLine() { $this->type(PhoneNumberType::FIXED_LINE); return $this; } /** * Enable automatic country detection. * * @return $this */ public function detect() { $this->detect = true; return $this; } /** * Enable lenient number checking. * * @return $this */ public function lenient() { $this->lenient = true; return $this; } /** * Convert the rule to a validation string. * * @return string */ public function __toString() { $parameters = implode(',', array_merge( $this->countries, static::parseTypes($this->types), ($this->countryField ? [$this->countryField]: []), ($this->detect ? ['AUTO'] : []), ($this->lenient ? ['LENIENT'] : []) )); return 'phone' . (! empty($parameters) ? ":$parameters" : ''); } }