App\Http\Controllers\User\ProfileController::update PHP 메소드

update() 공개 메소드

public update ( $userId, Illuminate\Http\Request $request )
$request Illuminate\Http\Request
    public function update($userId, Request $request)
    {
        // basic validation
        $this->validate($request, ['displayName' => 'required']);
        // member validation
        /** @var UserInterface $user */
        $user = $this->handler->users()->find($userId);
        if ($user === null) {
            throw new UserNotFoundException();
        }
        $displayName = $request->get('displayName');
        $introduction = $request->get('introduction');
        // displayName validation
        if ($user->getDisplayName() !== trim($displayName)) {
            $this->handler->validateDisplayName($displayName);
        }
        XeDB::beginTransaction();
        try {
            // resolve profile file
            if ($profileFile = $request->file('profileImgFile')) {
                /** @var UserImageHandler $imageHandler */
                $imageHandler = app('xe.user.image');
                $user->profileImageId = $imageHandler->updateUserProfileImage($user, $profileFile);
            }
            $this->handler->update($user, compact('displayName', 'introduction'));
        } catch (\Exception $e) {
            XeDB::rollback();
            throw $e;
        }
        XeDB::commit();
        return redirect()->route('user.profile', [$user->getId()])->with('alert', ['type' => 'success', 'message' => '변경되었습니다.']);
    }