maybe i do the inverse here?

This commit is contained in:
spencerrlongg 2024-02-14 00:52:50 -06:00
parent dcf2168454
commit 57a75e68b9
2 changed files with 7 additions and 7 deletions

View file

@ -102,7 +102,7 @@ class CustomFieldset extends Model
if ($field->element == 'checkbox') {
//Log::alert($field->formatFieldValuesAsArray());
$values = $field->formatFieldValuesAsArray();
//$rules[$field->db_column_name()] = 'checkboxes';
$rules[$field->db_column_name()] = 'checkboxes';
}
}

View file

@ -298,15 +298,15 @@ class ValidationServiceProvider extends ServiceProvider
});
Validator::extend('checkboxes', function ($attribute, $value, $parameters, $validator){
$options = CustomField::where('db_column', $attribute)->formatFieldValuesAsArray();
$options = CustomField::where('db_column', $attribute)->first()->formatFieldValuesAsArray();
// for legacy, allows users to submit a comma separated string of options
if(!is_array($value)) {
$exploded = explode(',', $value);
$valid = array_intersect($exploded, $options);
if(array_count_values($valid) > 0) {
return true;
$invalid = array_diff($exploded, $options);
if(count($invalid) > 0) {
return false;
}
}
if(is_array($value)) {
} else {
$valid = array_intersect($value, $options);
if(array_count_values($valid) > 0) {
return true;