Compare commits

...

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
d2873ebcc1 fix(wallets): capture $type in the deposit/withdraw action closure
The action closure referenced $type without importing it via use(), so
every credit/debit attempt in the admin panel threw "Undefined variable
$type" instead of adjusting the wallet.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-08 23:59:07 +03:30
3 changed files with 56 additions and 6 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

@@ -83,7 +83,7 @@ class WalletsTable
->maxLength(500)
->rows(2),
])
->action(function (Wallet $record, array $data, WalletService $walletService): void {
->action(function (Wallet $record, array $data, WalletService $walletService) use ($type): void {
$amount = (int) $data['amount'];
$description = filled($data['description'] ?? null) ? $data['description'] : null;

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']);
});