Nov 21, 2015
0
Level 3
FormRequest: Check if coupon code still within validity date using exists validation
Hello there,
I want to validate a coupon code. The database table looks like this:
Schema::create('coupons', function (Blueprint $table) {
$table->increments('id');
$table->text('code');
$table->date('valid_from');
$table->date('valid_until');
$table->text('discount_mrc');
$table->text('discount_otc');
$table->timestamps();
});
Now in my FormRequest validation I would like to check whether the provided coupon code exists in the database AND whether it is still valid, meaning whether it is within the valid_from to valid_until range.
I tried to limit it to the valid_until range first but even this I cannot do:
'coupon_code'=>'exists:coupons,code,valid_until,>=NOW()',
Any idea whether this works with the "exists" validation out of the box or whether I would have to create a custom validation?
Thanks Andreas
Please or to participate in this conversation.