/** * Edit User. * * @SWG\Patch( * path="/users/profile/{user_id}", * tags={"Users"}, * summary="Edit User", * @SWG\Response(response="200", description="Success", * @SWG\Schema( * title="data", * type="object", * required={"status", "user"}, * @SWG\Property(property="status", type="string", default="Record successfully updated.", description="Status message from server"), * @SWG\Property(property="user", ref="#/definitions/User"), * ) * ), * @SWG\Response(response="500", description="Could not update data", * @SWG\Schema( * title="data", * type="object", * @SWG\Property(property="error", type="string", default="could_not_update_data"), * ) * ), * @SWG\Parameter( * name="user_id", * in="path", * description="USER_ID to edit", * required=true, * type="integer", * default=8 * ), * @SWG\Parameter( * name="user", * in="body", * description="User object to edit", * required=true, * type="object", * @SWG\Schema(title="user", type="object", * @SWG\Property(property="user", ref="#/definitions/User") * ) * ) * ) * * @param UserRequest $request * * @return mixed * * @author Donna Borja <*****@*****.**> */ public function update(UserRequest $request) { $_user = $request->get('user'); // check if user exists $user = $this->user->whereId($request->user_id)->first(); if (!$user) { return API::response()->array(['status' => USER_DOES_NOT_EXIST])->statusCode(500); } // update users table try { $user_params = ['email' => $_user['email'], 'password' => bcrypt($_user['password'])]; $this->user->whereId($request->user_id)->update($user_params); } catch (Exception $e) { return API::response()->array(['status' => USER_UPDATE_FAIL])->statusCode(500); } // update user_information table try { $user_information_params = ['first_name' => $_user['first_name'], 'last_name' => $_user['last_name'], 'phone' => $_user['phone'], 'address' => $_user['address'], 'suburb' => $_user['suburb'], 'postcode' => $_user['postcode'], 'state_id' => $_user['state_id']]; $this->user_information->whereUserId($request->user_id)->update($user_information_params); } catch (Exception $e) { return API::response()->array(['status' => USER_UPDATE_FAIL])->statusCode(500); } // Exclude password information in returning data of what has been just updated unset($_user['password'], $_user['password_confirmation']); return API::response()->array(['status' => USER_UPDATE_SUCCESS, 'user' => $_user])->statusCode(200); }
/** * @param UserRequest $request * * @return \Illuminate\Http\JsonResponse * * @author Bertrand Kintanar <*****@*****.**> */ public function register(UserRequest $request) { $newUser = ['email' => $request->get('email'), 'password' => bcrypt($request->get('password'))]; $user = User::create($newUser); $token = JWTAuth::fromUser($user); return response()->json(compact('token')); }