Skip to main content

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

}

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...