*/ public function rules(): array { return [ 'customer_hashcode' => 'required|exists:customers,hashcode', 'campaign_id' => [ 'required', 'exists:campaigns,id', function (string $attribute, mixed $value, Closure $fail) { $campaign = Campaign::find($value); if ($campaign && $campaign->status === 0) { $fail("The selected {$attribute} is invalid."); } }, ], 'coupons' => [ Rule::requiredIf(function () { $campaign = Campaign::find($this->campaign_id); return $campaign->type === CampaignTypes::WALL ? true : false; }), function (string $attribute, mixed $value, Closure $fail) { foreach (explode(",", $value) as $coupon_id) { if (!is_int(intval($coupon_id)) or !intval($coupon_id) or intval($coupon_id) < 0) { $fail("The selected {$attribute} is invalid."); } } }, ] ]; } }