0

We have a Laravel 5.1 Restful Resource Controller (Let's say FooController) with all methods using route

api/foo/6/edit

We also have an Angular.js front-end app which uses restangular module to communicate with back-end.

However, when we try to post the data provided by the form to back-end; restangular sends the [PUT] request to:

/api/foo/6/edit/6

How can we modify the behaviour to change the PUT request url to '/api/foo/6' instead of '/api/foo/6/edit/6' while still using the edit route to get the edit data?

Here is the code used to get the edit data and update the changes:

Code:

find: function(id) {
    var defer = $q.defer();
    Restangular.one('foo', 6).one('edit').get().then(function(response) {
        defer.resolve(response);
    };

    return defer.promise;
},
save: function(data) {
    var defer = $q.defer();
    Restangular.all('foo').post(data).then(function(response) {
        defer.resolve(response);
    };
    return defer.promise;
}

1 Answer 1

1

Using Custom PUT instead solved the problem.

update: function(data) {
   var defer = $q.defer();
   Restangular.one('foo', 6).customPUT(data).then(function(response) {
       defer.resolve(response);
     }
   );

   return defer.promise;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.