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.

CreateDiscount.php 1.1KB

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