feat(usernames): update unique constraint to composite with type and provider

- Remove single unique constraint on username
  - Add composite unique constraint on username, username_type, and provider_type
  - Update Filament username form validation with custom unique rule
  - Add descriptive validation message for duplicate usernames
This commit is contained in:
idevakk
2025-12-09 10:14:50 -08:00
parent 1c4298cdaf
commit 4028a9a21e
2 changed files with 52 additions and 1 deletions

View File

@@ -9,7 +9,9 @@ use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\ToggleButtons;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Illuminate\Validation\Rules\Unique;
class UsernameForm
{
@@ -21,7 +23,19 @@ class UsernameForm
->columnSpan(1)
->alphaDash()
->helperText('Email: myusername@gmail.com | Username: myusername')
->required(),
->required()
->unique(
table: 'usernames',
ignoreRecord: true,
modifyRuleUsing: function (Unique $rule, Get $get) {
return $rule
->where('username_type', $get('username_type'))
->where('provider_type', $get('provider_type'));
},
)
->validationMessages([
'unique' => 'The username already exists for this type and provider.',
]),
TextInput::make('daily_mailbox_limit')
->integer()
->minValue(1)