- fix phone number format

This commit is contained in:
2023-07-30 11:42:07 +02:00
parent 010f8cf278
commit 127ebe79ae
3 changed files with 12 additions and 5 deletions

View File

@@ -14,7 +14,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
* @property string $token
* @property string $recipient
* @property string $email
* @property string $phoneNumber
* @property string|null $phoneNumber
* @property array $locations
* @property string|null $mission
* @property string|null $rodo
@@ -35,14 +35,21 @@ class CV extends Model
protected function phoneNumber(): Attribute
{
return Attribute::make(
get: fn (mixed $value, array $attributes): ?string => str_replace(' ', '', $attributes['phone_number'] ?? ''),
get: fn (mixed $value): string => str_replace(' ', '', $value ?? ''),
set: fn (mixed $value): string => str_replace(' ', '', $value ?? ''),
);
}
protected function formattedPhoneNumber(): Attribute
{
return Attribute::make(
get: fn (mixed $value, array $attributes): ?string => $attributes['phone_number'] ?? '',
get: function (mixed $value, array $attributes): ?string {
$number = str_replace(' ', '', $attributes['phone_number'] ?? '');
for ($i = 3; $i < 12; $i+=4) {
$number = substr_replace($number, ' ', $i, 0);
}
return $number;
},
);
}