0

I have error in here when i'm trying to update data using slim as API and angular as Client.

My slim codes :

<?php

$app->put("/update/:id",function($id)use($app){

    $body = $app->request->getBody();
    $user = json_decode($body);

    $newData = Users::find($id);
    $newData->username = $user->username;
    $newData->first_name = $user->first_name;
    $newData->last_name = $user->last_name;
    $newData->address = $user->address;
    echo $newData->save();
});

And my update angular codes :

app.controller('editUserController',function($scope, $http, $location, $routeParams){
    var id = $routeParams.id;
    $http.get('http://address.com/slimApi/index.php/cekOne/'+ id).success(function(response){
        $scope.users = response;
    });

    $scope.updateUser = function()
    {
        var r = confirm('Are you sure??');
        if (r==true) {
            $http.put('http://address.com/slimApi/index.php/update/' + id, $scope.users).success(function(response){
                $scope.users = '';
                $location.path('/');
            });
        } else{};
    }
});
alexw
  • 7,840
  • 6
  • 49
  • 85

0 Answers0