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.

CreateTax.php 1.0KB

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