07 February 2022

How to add form validation in multi step or role in laravel 8?

Add form validation in multi step or role in laravel 8 

Add validation, If input is not empty. 


if($role==2){


$bio = $res->bio;

$working_profile = $res->working_profile;

$experience = $res->experience;


$validator_array = array(

'f_name' => 'required',

'l_name' => 'required',

); 


}

else{


$validator_array = array(

'f_name' => 'required',

'l_name' => 'required',

); 

}

if($res->file('user_img')) {

$validator_array['user_img'] = 'required|image|mimes:jpeg,png,jpg,gif,svg';


}

$validator = Validator::make($res->all(),$validator_array);

 

if($validator->fails()){

//$vald_errors = $validator->errors(); 

$vald_message_bag=$validator->getMessageBag();

$vald_errors= webErrors($vald_message_bag->toArray());

$status=403;

$success=false;

$message='Invalid..!';

$errors=$vald_errors;

$result=array();

$result_obj=(object) array();

$extra=(object) array();

return webResponse($status,$success,$message,$errors,$result,$result_obj,$extra);

}

else{

// working code

}

No comments:

Post a Comment

How to add re-captcha v3 on all Elementor forms using coding?

 Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){     ?> <script src="https://www...