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.

EditTax.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Filament\Resources\TaxResource\Pages;
  3. use App\Filament\Resources\TaxResource;
  4. use App\Traits\HandlesResourceRecordUpdate;
  5. use Filament\Pages\Actions;
  6. use Filament\Resources\Pages\EditRecord;
  7. use Filament\Support\Exceptions\Halt;
  8. use Illuminate\Database\Eloquent\Model;
  9. use Illuminate\Support\Facades\Auth;
  10. class EditTax extends EditRecord
  11. {
  12. use HandlesResourceRecordUpdate;
  13. protected static string $resource = TaxResource::class;
  14. protected function getActions(): array
  15. {
  16. return [
  17. Actions\DeleteAction::make(),
  18. ];
  19. }
  20. protected function getRedirectUrl(): string
  21. {
  22. return $this->previousUrl;
  23. }
  24. protected function mutateFormDataBeforeUpdate(array $data): array
  25. {
  26. $data['enabled'] = (bool)$data['enabled'];
  27. return $data;
  28. }
  29. /**
  30. * @throws Halt
  31. */
  32. protected function handleRecordUpdate(Model $record, array $data): Model
  33. {
  34. $user = Auth::user();
  35. if (!$user) {
  36. throw new Halt('No authenticated user found.');
  37. }
  38. return $this->handleRecordUpdateWithUniqueField($record, $data, $user, 'type');
  39. }
  40. }