I needed a validation rules to check for the absence of a field on a table and thought negation would be useful in general, i.e:
!exists:user,id
I implemented it as follows: https://github.com/sooqini/framework/commit/fa50a03ae23b572c9cc2020d3cc9420a48141494
Most of the validation rules have corresponding negatives, so for example, the negative for exists is unique.
Yes I think every rule has an appropriate negation already.
Thanks, I didn't see unique, would be good to get the corresponding negatives linked in the docs
@taylorotwell
I may be wrong, but URL validation doesn't seem to have a negation. It would be interesting to have a validation rule to validate that the input provided WAS NOT an URL.
Use case:
It would be nice to have something like:
return [
'input_field_name' => 'required|!url'
];
Also, the present rule can't be negated, I had to write a custom validator for this.
@borys-p could you share your validator?
@isometriq sorry, can't find it now.
But you can write a custom Form Request class and use the (undocumented) method validator() to put your extra logic in. Then you have access to all request fields and can check if something is present, but it shouldn't be.
Yes i use that and sometimes validator::after()
have the exact same requirement as @dafonso for negation of validation
Same here, would love to see this implemented!
I have use of an URL negation. '!url' would be real handy! :)
Most helpful comment
Also, the
presentrule can't be negated, I had to write a custom validator for this.