您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CreateAccount.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Filament\Company\Resources\Banking\AccountResource\Pages;
  3. use App\Filament\Company\Resources\Banking\AccountResource;
  4. use App\Models\Banking\Account;
  5. use App\Traits\HandlesResourceRecordCreation;
  6. use Filament\Actions;
  7. use Filament\Resources\Pages\CreateRecord;
  8. use Filament\Support\Exceptions\Halt;
  9. use Illuminate\Database\Eloquent\Model;
  10. use Illuminate\Support\Facades\Auth;
  11. class CreateAccount extends CreateRecord
  12. {
  13. use HandlesResourceRecordCreation;
  14. protected static string $resource = AccountResource::class;
  15. protected function getRedirectUrl(): string
  16. {
  17. return $this->previousUrl;
  18. }
  19. protected function mutateFormDataBeforeCreate(array $data): array
  20. {
  21. $data['enabled'] = (bool)$data['enabled'];
  22. return $data;
  23. }
  24. /**
  25. * @throws Halt
  26. */
  27. protected function handleRecordCreation(array $data): Model
  28. {
  29. $user = Auth::user();
  30. if (!$user) {
  31. throw new Halt('No authenticated user found.');
  32. }
  33. return $this->handleRecordCreationWithUniqueField($data, new Account(), $user);
  34. }
  35. }