mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
initial stuff, need to switch branches
This commit is contained in:
parent
d55358652b
commit
dcf2168454
|
@ -5,6 +5,8 @@ namespace App\Models;
|
||||||
use Gate;
|
use Gate;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Watson\Validating\ValidatingTrait;
|
use Watson\Validating\ValidatingTrait;
|
||||||
|
|
||||||
class CustomFieldset extends Model
|
class CustomFieldset extends Model
|
||||||
|
@ -97,6 +99,11 @@ class CustomFieldset extends Model
|
||||||
if ($field->element != 'checkbox') {
|
if ($field->element != 'checkbox') {
|
||||||
$rules[$field->db_column_name()][] = 'not_array';
|
$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;
|
return $rules;
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Models\CustomField;
|
||||||
use App\Models\Department;
|
use App\Models\Department;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use DB;
|
use DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Validator;
|
use Validator;
|
||||||
|
@ -294,6 +296,25 @@ class ValidationServiceProvider extends ServiceProvider
|
||||||
Validator::extend('not_array', function ($attribute, $value, $parameters, $validator) {
|
Validator::extend('not_array', function ($attribute, $value, $parameters, $validator) {
|
||||||
return !is_array($value);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue