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 989B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Filament\Resources\DiscountResource\Pages;
  3. use App\Filament\Resources\DiscountResource;
  4. use App\Models\Setting\Discount;
  5. use App\Traits\HandlesResourceRecordCreation;
  6. use Filament\Resources\Pages\CreateRecord;
  7. use Illuminate\Database\Eloquent\Model;
  8. use Illuminate\Support\Facades\Auth;
  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['company_id'] = Auth::user()->currentCompany->id;
  20. $data['enabled'] = (bool)($data['enabled']);
  21. $data['created_by'] = Auth::id();
  22. return $data;
  23. }
  24. protected function handleRecordCreation(array $data): Model
  25. {
  26. return $this->handleRecordCreationWithUniqueField($data, new Discount(), 'type');
  27. }
  28. }