where('email', $this->row->user_email)->first(); if (isset($checkUser)) { $this->row->user_id = $checkUser->id; $this->row->status = ApplicationStatus::approved; $this->row->save(); return $this->response(); } $user->forceFill([ 'name' => $this->row->user_name . ' ' . $this->row->surname_name, 'username' => $this->row->user_email, 'email' => $this->row->user_email, 'phone' => $this->row->user_phone, 'password' => Hash::make('password'), ]); $user->save(); $this->row->user_id = $user->id; $this->row->status = ApplicationStatus::approved; $this->row->save(); $userRole = UniModel::model('core_roles') ->where('alias', 'user') ->first(); if (!empty($userRole)) { $userRoleModel = UniModel::model('core_user_roles'); $userRoleModel->forceFill([ 'user_id' => $user->id, 'role_id' => $userRole->id ]); $userRoleModel->save(); } $company = UniModel::model(config('platform.company.tables.company')) ->firstOrCreate([ 'name' => $this->row->user_name . ' ' . $this->row->surname_name, 'biniin' => $this->row->biniin ?? '', 'fullname' => $this->row->user_name . ' ' . $this->row->surname_name, 'segment' => 'sol' ]); $ucr = UniModel::model(config('platform.company.tables.company_user_role')) ->firstOrCreate([ 'user_id' => $user->id, 'role_id' => 7, 'company_id' => $company->id ]); if (!$ucr) { UniModel::model(config('platform.company.tables.company_user_role')) ->create([ 'user_id' => $user->id, 'role_id' => 6, 'company_id' => $company->id ]); } UniModel::model(config('platform.company.tables.company_user')) ->firstOrCreate([ 'company_id' => $company->id, 'user_id' => $user->id, 'default' => true, ]); return $this->response(); } }