public function updatePlatform($parameters)
 {
     try {
         $userLogs = new UserLogsService();
         switch ($parameters['oper']) {
             case 'changePassword':
                 $id = $parameters['id'];
                 $platform = Platform::find(reset($id));
                 $platform->api_password = $this->hashPassword($parameters['password']);
                 $platform->save();
                 $parameters['oper'] = 'apiChangePassword';
                 $userLogs->createUserLog($parameters);
                 return true;
                 break;
             case 'del':
                 $parameters['oper'] = 'apiDel';
                 $userLogs->createUserLog($parameters);
                 return Platform::destroy($parameters['ids']);
                 break;
             case 'add':
                 $platform = $this->newPlatform($parameters);
                 $parameters['oper'] = 'apiAdd';
                 $userLogs->createUserLog($parameters);
                 break;
             case 'edit':
                 $id = $parameters['id'];
                 $platform = Platform::find($id);
                 $parameters['oper'] = 'apiEdit';
                 $userLogs->createUserLog($parameters);
                 break;
         }
         $columns = array_intersect_key($parameters, array_flip($platform->getFillableColumns()));
         if (!empty($columns)) {
             $platform->update($columns);
         }
         return $platform;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 2
0
 public function updateUser($parameters)
 {
     try {
         $userLogs = new UserLogsService();
         switch ($parameters['oper']) {
             case 'changePassword':
                 $id = $parameters['id'];
                 $user = User::find(reset($id));
                 $validator = $this->getUserValidator($parameters, true, false, true);
                 if ($validator->fails()) {
                     throw new \Exception($validator->messages());
                 }
                 $user->password = $this->hashPassword($parameters['password']);
                 $user->save();
                 $userLogs->createUserLog($parameters);
                 return true;
                 break;
             case 'generateApiKey':
                 $id = $parameters['ids'];
                 $user = User::find(reset($id));
                 Artisan::call('api-key:generate', array('--user-id' => $user->id));
                 $userLogs->createUserLog($parameters);
                 return true;
                 break;
             case 'del':
                 $userLogs->createUserLog($parameters);
                 return User::destroy($parameters['ids']);
                 break;
             case 'add':
                 $user = $this->newUser($parameters);
                 $userLogs->createUserLog($parameters);
                 break;
             case 'edit':
                 //                    DB::table('campaign')->insert(
                 //                        array('id' => '572', 'name' => 'squaretraffic2')
                 //                    );
                 $id = $parameters['id'];
                 $user = User::find($id);
                 $validator = $this->getUserValidator($parameters, true, $user->email !== $parameters['email']);
                 if ($validator->fails()) {
                     throw new \Exception($validator->messages());
                 }
                 $userLogs->createUserLog($parameters);
                 break;
         }
         $columns = array_intersect_key($parameters, array_flip($user->getFillableColumns()));
         if (!empty($columns)) {
             $user->update($columns);
         }
         $relationships = array_intersect_key($parameters, array_flip(User::$relationshipsAllowedToUpdate));
         if (!empty($relationships)) {
             foreach ($relationships as $relationshipType => $relationshipValue) {
                 if (!empty($relationshipValue)) {
                     if (!is_array($relationshipValue)) {
                         $relationshipValue = explode(',', $relationshipValue);
                     }
                     $user->{$relationshipType}()->sync($relationshipValue);
                 }
             }
         }
         return $user;
     } catch (\Exception $e) {
         throw $e;
     }
 }