initial stuff, need to switch branches

This commit is contained in:
spencerrlongg 2024-02-13 19:35:37 -06:00
parent d55358652b
commit dcf2168454
2 changed files with 28 additions and 0 deletions

View file

@ -5,6 +5,8 @@ namespace App\Models;
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
@ -97,6 +99,11 @@ class CustomFieldset extends Model
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;

View file

@ -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;
@ -294,6 +296,25 @@ class ValidationServiceProvider extends ServiceProvider
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;
}
}
});
}
/**