You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EditAccount.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\HandlesResourceRecordUpdate;
  6. use Filament\Actions;
  7. use Filament\Resources\Pages\EditRecord;
  8. use Filament\Support\Exceptions\Halt;
  9. use Illuminate\Database\Eloquent\Model;
  10. use Illuminate\Support\Facades\Auth;
  11. class EditAccount extends EditRecord
  12. {
  13. use HandlesResourceRecordUpdate;
  14. protected static string $resource = AccountResource::class;
  15. protected function getHeaderActions(): array
  16. {
  17. return [
  18. Actions\DeleteAction::make(),
  19. ];
  20. }
  21. protected function getRedirectUrl(): ?string
  22. {
  23. return $this->previousUrl;
  24. }
  25. protected function mutateFormDataBeforeSave(array $data): array
  26. {
  27. $data['enabled'] = (bool) $data['enabled'];
  28. return $data;
  29. }
  30. /**
  31. * @throws Halt
  32. */
  33. protected function handleRecordUpdate(Account | Model $record, array $data): Model | Account
  34. {
  35. $user = Auth::user();
  36. if (! $user) {
  37. throw new Halt('No authenticated user found.');
  38. }
  39. return $this->handleRecordUpdateWithUniqueField($record, $data, $user);
  40. }
  41. }