angularjs - How to globally config Laravel's Route::resource to be compatible with ng.resource (a Laravel route for each ng resource)? -
laravl 5 uses put/patch
verbs update resource while angular ng.resource uses post
default both creation , update. how globally set laravel's route::resource
follow angular behavior (a laravel route each ng resource)?
(it's possible make angular compatible laraval, i'm not sure approach better.)
i don't know laravel's rest capabilities. still suggest modify angular's behaviour.
put
implementing put quite easy.
you can modify behaviour of ng-resource while creating factory $resource(url, parameters, actions), third parameter describes custom actions ...
in https://docs.angularjs.org/api/ngresource/service/$resource there example creating put method available update
on service , $update
on instance. :
app.factory('notes', function($resource) { return $resource('/notes/:id', null, { 'update': { method:'put' } }); }]); // in our controller id url using ngroute , $routeparams // pass in $routeparams , our notes factory along $scope app.controller('notesctrl', ['$scope', '$routeparams', 'notes', function($scope, $routeparams, notes) { // first note object factory var note = notes.get({ id:$routeparams.id }); $id = note.id; // call update passing in id first object updating notes.update({ id:$id }, note); // put /notes/id note object in request payload });
patch
creating patch behaviour theoretically possible, described here - partial updates (aka patch) using $resource based service?
but wouldn't ng-resource. can many things defining transformrequest or transformresponse function (i use utilizing java spring rest api). still ng-resource doesn't support patch on own if need i'd rather try different layer rest.
Comments
Post a Comment