diff --git a/src/Observers/User/UserCompanyObserver.php b/src/Observers/User/UserCompanyObserver.php new file mode 100644 index 0000000..47c9d5f --- /dev/null +++ b/src/Observers/User/UserCompanyObserver.php @@ -0,0 +1,43 @@ +loadMissing( + 'user', + ); + + if ($userCompany->user) { + event('eloquent.updated: App\Models\User', $userCompany->user); + } + } + + public function updated($userCompany) + { + if (!Config::get('iss-supernova.base_uri')) { + return; + } + + $userCompany->loadMissing( + 'user', + ); + + if ($userCompany->user) { + event('eloquent.updated: App\Models\User', $userCompany->user); + } + } + + public function deleted($user) + { + $this->updated($user); + } +} diff --git a/src/Observers/User/UserObserver.php b/src/Observers/User/UserObserver.php index 28ce1c3..7f5d2b0 100644 --- a/src/Observers/User/UserObserver.php +++ b/src/Observers/User/UserObserver.php @@ -30,6 +30,8 @@ public function created($user) //Supervisor $data['supervisor_uuid'] = config('hub.model_user')::query()->whereHas('user_companies', function ($query) use ($user) { + $query->where('company_id', $user->company_id); + //Usuário que tenha cargo de Supervisor $query->whereIn('position_id', self::getSupervisorPositionsFromCompany($user->company_id)->pluck('id')); @@ -54,6 +56,8 @@ public function created($user) //Gerente $data['manager_uuid'] = config('hub.model_user')::query()->whereHas('user_companies', function ($query) use ($user) { + $query->where('company_id', $user->company_id); + //Usuário que tenha cargo de Gerente $query->whereIn('position_id', self::getManagerPositionsFromCompany($user->company_id)->pluck('id')); @@ -124,6 +128,8 @@ public function updated($user) //Supervisor $data['supervisor_uuid'] = config('hub.model_user')::query()->whereHas('user_companies', function ($query) use ($user) { + $query->where('company_id', $user->company_id); + //Usuário que tenha cargo de Supervisor $query->whereIn('position_id', self::getSupervisorPositionsFromCompany($user->company_id)->pluck('id')); @@ -148,6 +154,8 @@ public function updated($user) //Gerente $data['manager_uuid'] = config('hub.model_user')::query()->whereHas('user_companies', function ($query) use ($user) { + $query->where('company_id', $user->company_id); + //Usuário que tenha cargo de Gerente $query->whereIn('position_id', self::getManagerPositionsFromCompany($user->company_id)->pluck('id'));