fix(users): pass mobile rule as a nested closure Filament can evaluate
Filament evaluates each entry of ->rules() as its own closure and tries to inject dependencies, so a bare Laravel validation closure blew up with "[$attribute] was unresolvable" when opening/saving the user form. Wrap it so the outer closure returns the Laravel rule. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,11 +28,13 @@ class UserForm
|
||||
->tel()
|
||||
->helperText('مثال درست: 09123456789')
|
||||
->dehydrateStateUsing(fn (?string $state): ?string => Mobile::normalize($state))
|
||||
->rules([static function (string $attribute, mixed $value, \Closure $fail): void {
|
||||
if (filled($value) && ! preg_match(Mobile::REGEX, (string) Mobile::normalize((string) $value))) {
|
||||
$fail('فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789');
|
||||
}
|
||||
}])
|
||||
->rules([
|
||||
fn (): \Closure => function (string $attribute, mixed $value, \Closure $fail): void {
|
||||
if (filled($value) && ! preg_match(Mobile::REGEX, (string) Mobile::normalize((string) $value))) {
|
||||
$fail('فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789');
|
||||
}
|
||||
},
|
||||
])
|
||||
->unique(ignoreRecord: true)
|
||||
->maxLength(20),
|
||||
TextInput::make('password')
|
||||
|
||||
Reference in New Issue
Block a user