UPDATE

  1. Define appropriate route.

    demo_photos-update:
       path:         api/demo/photos/{uid}
       controller:   Vendor\Demo\Controller\PhotoApiController::update
       methods:      PUT
       format:       json
       requirements:
          uid:       \d+
       defaults:
          plugin:    PhotoApi
          data:
       options:
          middleware:
             - auth
    

    Warning

    If you extend LMSFacadeControllerAbstractApiController,

    uid must be present and it’s name should not be changed.

    Tip

    update action has been already implemented in our predefined controller.

    PUT is not required, but as we follow the concept, we should always use it.

    json is not required, but it gives a little bit of clarity.

    requirements has uid argument and tells us it must be of type integer.

    data is required argument here, as we later pass data that will be placed inside data argument.

    auth FE user session is required as well as proper csrf token.

  2. Use defined above endpoint in JavaScript scope.

    updateResource('/api/demo/photos/1', {title: 'Title 1'}).then(function (isOk) {
       console.log(isOk);
    });
    

    Tip

    updateResource function has been already implemented in our predefined Routes.js.