Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular无法读取属性';车身';未定义的_Javascript_Php_Angularjs_Laravel - Fatal编程技术网

Javascript Angular无法读取属性';车身';未定义的

Javascript Angular无法读取属性';车身';未定义的,javascript,php,angularjs,laravel,Javascript,Php,Angularjs,Laravel,我遇到了一个错误,我不确定是什么问题 angular.js:14642 TypeError:无法读取未定义的属性“body” 我正在尝试异步更新帖子。我可以异步地添加、获取、删除帖子,只需要为update函数这样做 main.js $scope.updatePost = function(post){ $http.post('/auth/upost/' + post.id, { body: $scope.post.body, }).then(function(

我遇到了一个错误,我不确定是什么问题

angular.js:14642 TypeError:无法读取未定义的属性“body”

我正在尝试异步更新帖子。我可以异步地添加、获取、删除帖子,只需要为update函数这样做

main.js

$scope.updatePost = function(post){

    $http.post('/auth/upost/' + post.id, {
        body: $scope.post.body, 
    }).then(function(data){
        console.log(data);
        $scope.myposts.push(data.data);
    });



};
路线

Route::post('auth/upost/{post}','PostController@update')->name('update.post')

PostController.php

public function update(Post $post)
{
    //
    $data = request()->validate([
        'body' => 'required|string'
    ]);


    $post->update($data);

    $response = new Response(json_encode($post));
    $response->headers->set('Content-Type', 'application/json'); 

    return $response;

}
html

<div id="mypost" class="col-md-8 panel-default" ng-repeat="post in myposts ">
    <div id="eli-style-heading" class="panel-heading"><% post.user.name %></div>
    <div class="panel-body panel">
        <figure>
            <p ng-model="post.body" editable-text="post.body" e-form="textBtnForm"> <% post.body %></p>
            <p>  <% post.created_at %></p>
        </figure>
        <span>

         <i style="color:red;" class="glyphicon glyphicon-remove" ng-click="deletePost(post)" ng-if="post.deletable"></i>

              <button class="btn btn-default" ng-click="textBtnForm.$show()" ng-hide="textBtnForm.$visible">
                edit
              </button>
            <span><button type="submit" class="btn btn-primary" ng-click="updatePost(post)">Update</button></span>
        </span>
    </div>
</div>

编辑 更新
正确的代码,我不得不删除$scope,不知道为什么,但它可以工作

Main.js

$scope.updatePost = function(post){

    $http.post('/auth/upost/' + post.id, {
        body: post.body

    }).then(function(data, status, headers, config){
        console.log(data);  


    });




};

你需要body:$scope.body,?我需要传递更新后的body内容,你认为我应该怎么做?关于$http.post('/auth/upost/'+post.id,{body:post,})@Sajeetharan我现在知道了
angular.js:12701 posthttp://127.0.0.1:8000/auth/upost/36 422(不可处理实体)
我得到了这个
{body:[“正文必须是字符串。”]}