- fix phone number format
This commit is contained in:
@@ -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;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user