2017-01-01 16 views
0

これは私の形態PUT方法にlaravalと角度に許可されていない方法

<form class="form-horizontal alert alert-info" id="editForm" ng-submit="updateComment(currentComment)" hidden> 
      <h3 class="text-center">Update Comment Details</h3> 
      <div class="form-group"> 
       <label for="Name">Author Name:</label> 
       <input type="text" class="form-control" ng-model="currentComment.author" value="{{currentComment.author}}"> 
      </div> 
      <div class="form-group"> 
       <label for="text">Comment Text:</label> 
       <input type="text" class="form-control" ng-model="currentComment.text" value="{{currentComment.text}}"> 
      </div> 
      <input name="_method" type="hidden" value="PUT"> 
      <div class="form-group"> 
       <button class="btn btn-warning" ng-disabled="" ng-click="">Update</button> 
       <button class="btn btn-warning" ng-disabled="" ng-click="HideEditForm()">Cancel</button> 
      </div> 
     </form> 

であるこれは私のサービス

angular.module('commentService', []) 

    .factory('Comment', function($http) { 

     return { 
      get : function() { 
       return $http.get('api/comments'); 
      }, 
      show : function(id) { 
       return $http.get('api/comments/' + id); 
      }, 
      save : function(commentData) { 
       return $http({ 
        method: 'POST', 
        url: 'api/comments', 
        headers: { 'Content-Type' : 'application/x-www-form-urlencoded' }, 
        data: $.param(commentData) 
       }); 
      }, 
      update : function(commentData) { 
       return $http({ 
        method: 'PUT', 
        url: 'api/comments', 
        headers: { 'Content-Type' : 'application/x-www-form-urlencoded' }, 
        data: $.param(commentData) 
       }); 
      }, 
      destroy : function(id) { 
       return $http.delete('api/comments/' + id); 
      } 
     } 

    }); 

であり、これは私の角度JSコントローラ

angular.module('mainCtrl', ['datatables']) 

    .controller('mainController', function($scope, $http, Comment) { 
     // object to hold all the data for the new comment form 
     $scope.commentData = {}; 

     // loading variable to show the spinning loading icon 
     $scope.loading = true; 

     // get all the comments first and bind it to the $scope.comments object 
     Comment.get() 
      .success(function(data) { 
       $scope.comments = data; 
       $scope.loading = false; 
      }); 


     // function to handle editing the form 
     $scope.currentComment = {}; 
     $scope.editForm = function(id){ 
      Comment.show(id).success(function(data){ 
       $scope.currentComment = data; 
       $('#empForm').slideUp(); 
       $('#editForm').slideToggle(); 
      }); 

     }; 

     $scope.updateComment = function(commentData){ 
      Comment.update(commentData).success(function(data){ 
      }); 
     }; 

     //hide edit form 
     $scope.HideEditForm = function(){ 
      $('#editForm').slideToggle(); 
     }; 
     // function to handle submitting the form 
     $scope.submitComment = function() { 
      $scope.loading = true; 

      // save the comment. pass in comment data from the form 
      Comment.save($scope.commentData) 
       .success(function(data) { 
        $scope.commentData = {}; 
        // if successful, we'll need to refresh the comment list 
        Comment.get() 
         .success(function(getData) { 
          $scope.comments = getData; 
          $scope.loading = false; 
         }); 

       }) 
       .error(function(data) { 
        console.log(data); 
       }); 
     }; 

     // function to handle deleting a comment 
     $scope.deleteComment = function(id) { 
      $scope.loading = true; 

      Comment.destroy(id) 
       .success(function(data) { 

        // if successful, we'll need to refresh the comment list 
        Comment.get() 
         .success(function(getData) { 
          $scope.comments = getData; 
          $scope.loading = false; 
         }); 

       }); 
     }; 

    }); 

とこれは私のコントローラです

<?php 

class CommentController extends \BaseController { 

    /** 
    * Send back all comments as JSON 
    * 
    * @return Response 
    */ 
    public function index() 
    { 
     return Response::json(Comment::get()); 
    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @return Response 
    */ 
    public function store() 
    { 
     Comment::create(array(
      'author' => Input::get('author'), 
      'text' => Input::get('text') 
     )); 

     return Response::json(array('success' => true)); 
    } 

    /** 
    * update a resource in storage. 
    * 
    * @return Response 
    */ 
    public function update() 
    { 
     Comment::where('id', Input::get('author'))->update(['author'=>Input::get('author'), 'text'=>Input::get('text')]); 

     return Response::json(array('success' => true)); 
    } 

    /** 
    * Return the specified resource using JSON 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function show($id) 
    { 
     return Response::json(Comment::find($id)); 
    } 

    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function destroy($id) 
    { 
     Comment::destroy($id); 

     return Response::json(array('success' => true)); 
    } 

} 

すべての方法は、私はあなたがポストを使用することができ、あなたのケースでは、事前

答えて

0

に問題のおかげを整理するために私を助けてください、角に新しいですPUTメソッドを除いて動作しますが、あなたは新しいフィールドの名前_method = PUTを追加する必要がありますご要望に応じて(commentData

enter image description here

+0

ええ、私はポストを使用することができます知っているが、私は残りのAPI規則を使用したい... – hu7sy

+0

その後、あなたはx-www-form-urlencodedではなく、フォーム - を使用しなければなりませんデータ、そのth他の回答 –

+0

私はそれを使用しています兄弟あなたは私の更新機能をサービスで見ることができます – hu7sy

関連する問題