Files
hoshpoint-backend/app/Filament/Resources/Users/Schemas/UserForm.php
soheil khaledabadi f31f87aaf6 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>
2026-09-09 00:38:22 +03:30

57 lines
2.2 KiB
PHP

<?php
namespace App\Filament\Resources\Users\Schemas;
use App\Support\Mobile;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
class UserForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
TextInput::make('name')
->label('نام')
->required()
->maxLength(255),
TextInput::make('email')
->label('ایمیل')
->email()
->required()
->unique(ignoreRecord: true)
->maxLength(255),
TextInput::make('mobile')
->label('شماره موبایل')
->tel()
->helperText('مثال درست: 09123456789')
->dehydrateStateUsing(fn (?string $state): ?string => Mobile::normalize($state))
->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')
->label('رمز عبور')
->password()
->revealable()
->autocomplete('new-password')
->required(fn (string $operation): bool => $operation === 'create')
->saved(fn (?string $state): bool => filled($state))
->maxLength(255),
CheckboxList::make('roles')
->label('نقش‌ها')
->relationship(titleAttribute: 'name')
->searchable()
->bulkToggleable()
->columns(2),
]);
}
}