Skip to content

Instantly share code, notes, and snippets.

@drakakisgeo
Created September 25, 2012 16:52
Show Gist options
  • Save drakakisgeo/3783103 to your computer and use it in GitHub Desktop.
Save drakakisgeo/3783103 to your computer and use it in GitHub Desktop.
Laravel:Grab any input that starts with a $string and create validation rules array
function get_jsfields($input,$begins_with,$numpos,$validation_string){
$jsfields = array();
$getkeys = array_keys($input);
for($i=0;$i<sizeof($getkeys);$i++){
if(preg_match("/$begins_with/i", trim($getkeys[$i]))){
$jsfields[$begins_with.$getkeys[$i][$numpos-1]] = ''.$validation_string.'';
}
}
return $jsfields;
}
///// After this only thing you have to do is merge this returned array with your $rules array.
//// Usage example: $rules = array_merge($rules, get_jsfields($input,"date_",6,"required|date"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment