3 Commits

Author SHA1 Message Date
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
ac11fbeaa6 Merge pull request 'fix(wallets): capture $type in the deposit/withdraw action closure' (#2) from feat/persian-panel-fixes-and-model-tweaks into main
Reviewed-on: #2
2026-09-08 20:45:31 +00:00
84fe0e5d18 Merge pull request 'feat: Persian panel/API fixes and structural-model tweaks' (#1) from feat/persian-panel-fixes-and-model-tweaks into main
Reviewed-on: #1
2026-09-08 20:10:50 +00:00
2 changed files with 55 additions and 5 deletions

View File

@@ -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')

View File

@@ -0,0 +1,48 @@
<?php
use App\Filament\Resources\Users\Pages\CreateUser;
use App\Models\Role;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\actingAs;
uses(RefreshDatabase::class);
beforeEach(function (): void {
Filament::setCurrentPanel(Filament::getDefaultPanel());
$admin = User::factory()->create();
$role = Role::query()->firstOrCreate(['slug' => 'admin'], ['name' => 'مدیر']);
$admin->roles()->sync([$role->id]);
actingAs($admin);
});
it('opens the create user form without the unresolvable-closure error', function (): void {
Livewire\Livewire::test(CreateUser::class)
->assertOk();
});
it('accepts a +98 mobile and normalizes it, rejects a malformed one', function (): void {
Livewire\Livewire::test(CreateUser::class)
->fillForm([
'name' => 'کاربر تست',
'email' => 'ok@example.com',
'mobile' => '+98 912 345 6789',
'password' => 'password12',
])
->call('create')
->assertHasNoFormErrors();
expect(User::query()->where('email', 'ok@example.com')->value('mobile'))->toBe('09123456789');
Livewire\Livewire::test(CreateUser::class)
->fillForm([
'name' => 'کاربر بد',
'email' => 'bad@example.com',
'mobile' => '123',
'password' => 'password12',
])
->call('create')
->assertHasFormErrors(['mobile']);
});