Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a string is "0" with Laravel validation

How can I check if a value of a string is "0" in Laravel 5.3?

Here's my validation rules before processing the data:

// I want them to be anything but "0". So "01", "1" etc. are all okay
$rules = [
    'state' => 'required',
    'city' => 'required',
];

As the data is passed as strings I cannot use min:1 for this.

I'm sorry if this have already been asked, but I cannot find an answer. Many thanks!

like image 532
snubbus Avatar asked Mar 18 '17 09:03

snubbus


1 Answers

This worked for me:

$rules = [
    'state' => 'required|not_in:0',
    'city' => 'required|not_in:0',
];

Also, have a look at this: Laravel 5.2 validation check if value is not equal to a variable

like image 100
snubbus Avatar answered Oct 22 '22 13:10

snubbus