mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
Merge pull request #13880 from Godmartinz/department-validation-bug
Fixed department validation to allow updates
This commit is contained in:
commit
7b7d424962
|
@ -279,7 +279,24 @@ class ValidationServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
Validator::extend('is_unique_department', function ($attribute, $value, $parameters, $validator) {
|
Validator::extend('is_unique_department', function ($attribute, $value, $parameters, $validator) {
|
||||||
$data = $validator->getData();
|
$data = $validator->getData();
|
||||||
if ((array_key_exists('location_id', $data) && $data['location_id'] != null) && (array_key_exists('company_id', $data) && $data['company_id'] != null)) {
|
|
||||||
|
if (
|
||||||
|
array_key_exists('location_id', $data) && $data['location_id'] !== null &&
|
||||||
|
array_key_exists('company_id', $data) && $data['company_id'] !== null
|
||||||
|
) {
|
||||||
|
//for updating existing departments
|
||||||
|
if(array_key_exists('id', $data) && $data['id'] !== null){
|
||||||
|
$count = Department::where('name', $data['name'])
|
||||||
|
->where('location_id', $data['location_id'])
|
||||||
|
->where('company_id', $data['company_id'])
|
||||||
|
->whereNotNull('company_id')
|
||||||
|
->whereNotNull('location_id')
|
||||||
|
->where('id', '!=', $data['id'])
|
||||||
|
->count('name');
|
||||||
|
|
||||||
|
return $count < 1;
|
||||||
|
}else // for entering in new departments
|
||||||
|
{
|
||||||
$count = Department::where('name', $data['name'])
|
$count = Department::where('name', $data['name'])
|
||||||
->where('location_id', $data['location_id'])
|
->where('location_id', $data['location_id'])
|
||||||
->where('company_id', $data['company_id'])
|
->where('company_id', $data['company_id'])
|
||||||
|
@ -289,9 +306,10 @@ class ValidationServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
return $count < 1;
|
return $count < 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Validator::extend('not_array', function ($attribute, $value, $parameters, $validator) {
|
Validator::extend('not_array', function ($attribute, $value, $parameters, $validator) {
|
||||||
|
|
Loading…
Reference in a new issue