When having this validation, it'll check if the coupon exists in the discounts table in the "code" column:
$this->validate($request, [
'coupon' => 'required|exists:discounts,code',
]);
That works fine, but when a code is soft-deleted already in the table, it still thinks that it exists... but it doesn't.
Make an exists-validation, add a value in the database, soft delete it and run the validation.
You can use Rule::exists('discounts', 'code')->whereNull('deleted_at') to check for only undeleted items.
@themsaid why close it? it's a bug. what you offer is a workaround.
No it's not, the Validator knows nothing about Eloquent, you need to instruct it about soft deletion if you support soft deletion.
Think of the Validator as a separate component from Eloquent, it just looks into a DB table that's all it knows. Happy to help if you need any further assistance :)
Most helpful comment
You can use
Rule::exists('discounts', 'code')->whereNull('deleted_at')to check for only undeleted items.