Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
<?php
namespace HiEvents\Http\Request\PromoCode;
use HiEvents\DomainObjects\Enums\PromoCodeDiscountAppliesToEnum;
use HiEvents\DomainObjects\Enums\PromoCodeDiscountTypeEnum;
use HiEvents\Http\Request\BaseRequest;
use Illuminate\Validation\Rule;
class CreateUpdatePromoCodeRequest extends BaseRequest
{
public function rules(): array
{
return [
'code' => 'min:2|string|required|max:50',
'applicable_product_ids' => 'array',
'discount' => [
'required_if:discount_type,PERCENTAGE,FIXED',
'numeric',
'min:0',
function ($attribute, $value, $fail) {
if ($this->input('discount_type') === PromoCodeDiscountTypeEnum::PERCENTAGE->name && $value > 100) {
$fail('The discount percentage must be less than or equal to 100%.');
}
},
],
'expiry_date' => 'date|nullable',
'max_allowed_usages' => 'nullable|gte:1|max:9999999',
'discount_type' => [
'required',
Rule::in(PromoCodeDiscountTypeEnum::valuesArray()),
],
'discount_applies_to' => [
'sometimes',
Rule::in(PromoCodeDiscountAppliesToEnum::valuesArray()),
],
];
}
}