Skip to content

Commit

Permalink
initial stuff, need to switch branches
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerrlongg committed Feb 14, 2024
1 parent d553586 commit dcf2168
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/Models/CustomFieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Gate;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\Rule;
use Watson\Validating\ValidatingTrait;

class CustomFieldset extends Model
Expand Down Expand Up @@ -97,6 +99,11 @@ public function validation_rules()
if ($field->element != 'checkbox') {
$rules[$field->db_column_name()][] = 'not_array';
}
if ($field->element == 'checkbox') {
//Log::alert($field->formatFieldValuesAsArray());
$values = $field->formatFieldValuesAsArray();
//$rules[$field->db_column_name()] = 'checkboxes';
}
}

return $rules;
Expand Down
21 changes: 21 additions & 0 deletions app/Providers/ValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace App\Providers;

use App\Models\CustomField;
use App\Models\Department;
use App\Models\Setting;
use DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Rule;
use Validator;
Expand Down Expand Up @@ -294,6 +296,25 @@ public function boot()
Validator::extend('not_array', function ($attribute, $value, $parameters, $validator) {
return !is_array($value);
});

Validator::extend('checkboxes', function ($attribute, $value, $parameters, $validator){
$options = CustomField::where('db_column', $attribute)->formatFieldValuesAsArray();
if(!is_array($value)) {
$exploded = explode(',', $value);
$valid = array_intersect($exploded, $options);
if(array_count_values($valid) > 0) {
return true;
}
}
if(is_array($value)) {
$valid = array_intersect($value, $options);
if(array_count_values($valid) > 0) {
return true;
}
}


});
}

/**
Expand Down

0 comments on commit dcf2168

Please sign in to comment.