Exemple #1
0
 /**
  * Put an entity.
  *
  * @param  string   $id
  * @param  Request  $request
  * @return Response
  */
 public function putOne(Request $request, $id)
 {
     // Extract the credentials
     $credential = $request->get('_user_credential', []);
     // Extract the profile
     $profile = $request->get('_user_profile', []);
     // Set new users to guest
     $request->merge(['user_type' => 'guest']);
     if ($this->getModel()->find($id)) {
         throw new ValidationException(new MessageBag(['uuid' => 'Users are not permitted to be replaced.']));
     }
     /** @var User $model */
     $model = $this->getModel()->newInstance();
     $this->validateRequest($request->all(), $this->getValidationRules());
     $model->fill($request->all());
     $model->save();
     // Finally create the credentials
     $this->validateRequest($credential, UserCredential::getValidationRules());
     $model->setCredential(new UserCredential($credential));
     // Finally create the profile if it exists
     if (!empty($profile)) {
         $this->validateRequest($profile, UserProfile::getValidationRules());
         $model->setProfile(new UserProfile($profile));
     }
     return $this->getResponse()->transformer($this->getTransformer())->createdItem($model);
 }