A free open source IT asset/license management system
allows validation to ignore self and update
Godfrey M6d65f6646f43
diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.phpindex 70fa64702e..fffb571eee 100644--- a/app/Providers/ValidationServiceProvider.php+++ b/app/Providers/ValidationServiceProvider.php@@ -218,19 +218,37 @@ class ValidationServiceProvider extends ServiceProviderValidator::extend('is_unique_department', function ($attribute, $value, $parameters, $validator) {$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();++ return $count < 1;+ }else // for entering in new departments+ {$count = Department::where('name', $data['name'])->where('location_id', $data['location_id'])->where('company_id', $data['company_id'])->whereNotNull('company_id')->whereNotNull('location_id')- ->count('name');+ ->count();return $count < 1;}+ }else {return true;- }+ }});Validator::extend('not_array', function ($attribute, $value, $parameters, $validator) {