laravel angular 添加 post 500 错误

laravel angular add post 500 error

我正在尝试使用 angular 提交 post,我正在关注此 tutorial,但出现以下错误。

$http.post(...).success is not a function Failed to load resource: the server responded with a status of 500 (Internal Server Error)

$http.post(...).success is not a function at b.$scope.addPost (main.js:18)

这是路线:

Route::post('auth/post', 'PostController@storePost')->name('add.post');

后控制器

public function storePost(Request $request)
{
    $data = request()->validate([
     'title' => 'required|max:120',
     'body' => 'required|max:1000'
    ]);

    $data['user_id'] = auth()->user()->id;

    $post = Post::create($data);


    // return redirect('/home')->withMessage('A new post was created.');

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

Main.js

app.controller('mainCtrl', ['$scope', '$http', function($scope, $http){
    $scope.posts = {};

    $scope.addPost = function(){
        $http.post('/auth/post', {
            title: $scope.mytitle,
            body: $scope.mybody

        }).success(function(data, status, headers, config){
            $scope.posts.push(data);
            $scope.post = '';


        });

    };
}]);

我把success改成then,成功了

app.controller('mainCtrl', ['$scope', '$http', function($scope, $http){
    $scope.posts = {};

    $scope.addPost = function(){
        $http.post('/auth/post', {
            title: $scope.mytitle,
            body: $scope.mybody

        }).then(function(data, status, headers, config){
            $scope.posts.push(data);
            $scope.post = '';


        });

    };
}]);