Angularjs 角度法中不允许使用laravel作为PUT方法

Angularjs 角度法中不允许使用laravel作为PUT方法,angularjs,laravel,put,Angularjs,Laravel,Put,这是我的表格 <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">

这是我的表格

<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>
这是我的角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));
    }

}

对于您的案例,您可以使用post,但您应该在请求中添加名为_method=PUT的新字段(commentData


那么您必须使用x-www-form-urlencoded而不是表单数据,我正在使用的另一个答案是brother u可以在服务中看到我的更新函数我可以看到您的路由匹配吗?路由::组(数组('prefix'=>'api'),函数(){Route::resource('comments','CommentController');});嗯,我不确定,但我建议您首先使用Postman或其他http/rest客户端检查API,祝您好运
<?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));
    }

}