Framework: [Proposal] Allow simple negation of validation rules with ! prefix

Created on 3 Jan 2014  路  11Comments  路  Source: laravel/framework

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 helpful comment

Also, the present rule can't be negated, I had to write a custom validator for this.

All 11 comments

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! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lzp819739483 picture lzp819739483  路  3Comments

CupOfTea696 picture CupOfTea696  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

JamborJan picture JamborJan  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments