Check if a form field exists when doing form validation? Laravel 5 -


i have form has conditional logic displays or hides each field. want validate fields shown. see field list in validation script below , imagine hide "phone" form field in using conditional logic in view — still want validate rest of fields, if "phone" validation still there, script fails , shows error message saying "the phone number required."

in laravel 5, there way check if form field exists or change whether it's required or not dynamically before or when validating form?

here's validation code...

        $v = validator::make(input()->all(), [             'firstname' => 'required|min:1|max:80',             'lastname'  => 'required|min:1|max:80',             'address'  => 'required|min:10|max:80',             'address2'  => 'max:20',             'city'  => 'required|min:2|max:80',             'state'  => 'required|min:2|max:80',             'zip'  => 'required|min:5',             'phone'  => 'required|regex:'.validphoneregex(),         ]);         if($v->fails())         {             return redirect()->back()->witherrors($v)->withinput(input()->all());         } 

the following validation rule should job:

'phone'  => 'sometimes|regex:'.validphoneregex(), 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -