So, this is what i've tried already.
$regex = '/^(https?:\/\/)?([\da-z\.-] )\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/';
$rules = [
'nextcontactSchool' => 'nullable|digits_between:7,10',
'websiteSchool' => 'nullable|regex:' . $regex,
];
I did this in a controller once i figured that i can't properly make use of a rule. But the problem here is that, I cant seem to pass the empty data to the database and everytime that i do that, i get a error message.
Can you please help me out?
CodePudding user response:
You can use nullable and it will pass if websiteSchool and nextcontactSchool are not present
$request->validate([
'websiteSchool' => ['nullable', 'url'],
'nextcontactSchool' => ['nullable', 'digits_between:7,10']
]);
If this is not what you need, consider the following validation methods:
CodePudding user response:
so, i came to know the answer behind it. when using nullable it sends a null value for sure but it send's the nullable value in terms of a string. so rather than comparing it to null, we would be comparing it to 'null'.
e.g:
if($variable!='null'){
//do something
}