From 2e56f4d305905e44cf2681bd1b1ceea3bd4b545f Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 3 Mar 2023 00:22:08 +0100 Subject: [PATCH] Add trait --- src/HasPhoneNumbers.php | 23 +++++++++++++++++++++++ src/ValidPhoneRule.php | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/HasPhoneNumbers.php diff --git a/src/HasPhoneNumbers.php b/src/HasPhoneNumbers.php new file mode 100644 index 0000000..82fbf7d --- /dev/null +++ b/src/HasPhoneNumbers.php @@ -0,0 +1,23 @@ + + */ + abstract public function phoneNumbers(): array; + + public function updatePhoneNumbers(): self + { + foreach ($this->phoneNumbers() as $property) { + $this->setAttribute( + $property, + app(Formatter::class)->format($this->getAttribute($property)) + ); + } + + return $this; + } +} diff --git a/src/ValidPhoneRule.php b/src/ValidPhoneRule.php index 25d4da6..5d57e4a 100644 --- a/src/ValidPhoneRule.php +++ b/src/ValidPhoneRule.php @@ -38,6 +38,6 @@ class ValidPhoneRule implements Rule */ public function message() { - return __('validation.phone_number', ['name' => $this->attribute]); + return __('validation.phone_number', ['attribute' => $this->attribute]); } }