Skip to content

Commit

Permalink
Update PhoneParseE164Column.php
Browse files Browse the repository at this point in the history
  • Loading branch information
tanthammar committed Mar 3, 2023
1 parent 3203c14 commit d5506eb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Tables/PhoneParseE164Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@

use Brick\PhoneNumber\PhoneNumber;
use Brick\PhoneNumber\PhoneNumberFormat;
use Brick\PhoneNumber\PhoneNumberParseException;
use Filament\Tables\Columns\TextColumn;

/** requires E164 formatted phone number */
class PhoneParseE164Column
{
public static function make(string $column, PhoneNumberFormat|int $format = PhoneNumberFormat::INTERNATIONAL): TextColumn
{
return TextColumn::make($column)->formatStateUsing(fn ($state): string => PhoneNumber::parse($state)->format($format));
return TextColumn::make($column)->formatStateUsing(
function ($state) use ($format): string {
try {
return PhoneNumber::parse($state);
} catch (PhoneNumberParseException $e) {
return $state;
}
});
}
}

0 comments on commit d5506eb

Please sign in to comment.