How to display masked value in table columns?

I have an input for a phone like this:
TextInput::make('mobile_phone')->mask(fn (TextInput\Mask $mask) => $mask->pattern('(000) 000-0000'))
TextInput::make('mobile_phone')->mask(fn (TextInput\Mask $mask) => $mask->pattern('(000) 000-0000'))
But in the table, it is showing plain digits like "2223334444" (because that is what stored in the db). I guess there's a better way to handle columns like this before I experiment ->formatStateUsing method?
3 Replies
vahnmarty
vahnmartyOP2y ago
Here's my solution (using chatgpt)
->formatStateUsing(fn(string $state) => preg_replace('/(\d{3})(\d{3})(\d{4})/', '($1) $2-$3', $state)),
->formatStateUsing(fn(string $state) => preg_replace('/(\d{3})(\d{3})(\d{4})/', '($1) $2-$3', $state)),
LeandroFerreira
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
LeandroFerreira
https://packagist.org/packages/propaganistas/laravel-phone I've never used this before, but you can try
propaganistas/laravel-phone - Packagist
Adds phone number functionality to Laravel based on Google's libphonenumber API.
Want results from more Discord servers?
Add your server