Reputation: 1999
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;
}
Upvotes: 0
Views: 398
Reputation: 1999
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;
}
Upvotes: 1