文章审核,数据库已经更新了,但是网页不更新,status显示500错误

来源:14-3 使用全局scope进行软删除模型

慕慕5403139

2017-12-15

Chrome:

Request URL:

http://127.0.0.1:8000/admin/posts/51/status

Request Method:

POST

Status Code:

500 Internal Server Error

Remote Address:

127.0.0.1:8000

Referrer Policy:

no-referrer-when-downgrade

post/index.blade.php

@foreach($posts as $post)
   <tr>
       <td>{{$post->id}}.</td>
       <td>{{$post->title}}</td>
       <td>
           <button type="button" class="btn btn-block btn-default post-audit" post-id="{{$post->id}}" post-action-status="1" >通过</button>
           <button type="button" class="btn btn-block btn-default post-audit" post-id="{{$post->id}}" post-action-status="-1" >拒绝</button>
       </td>
   </tr>
@endforeach

PostController@status

public function status(Post $post)
{
   $this->validate(request(), [
       "status" => 'required|in:-1,1',
   ]);

   $post->status = request('status');
   $post->save();
   return [
       'error' => 0,
       'msg' => ''
   ];
}

写回答

1回答

慕慕5403139

提问者

2017-12-15

javascript如下:
/* ajax csrf-token */
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

$(".post-audit").click(function (event) {
    target = $(event.target);
    var post_id = target.attr("post-id");
    var status = target.attr("post-action-status");

    $.ajax({
        url: "/admin/posts/" + post_id + "/status",
        method: "POST",
        data: { "status": status },
        dataType: "json",
        success: function success(data) {
            if (data.error != 0) {
                alert(data.msg);
                return;
            }

            target.parent().parent().remove();
        }
    });
});


0
1
慕慕5403139
晕,查了一天才发现$post->save();报错,用tinker发现Elasticsearch\Common\Exceptions\Curl\CouldNotConnectToHost with message 'cURL error 7: Failed to connect to 127.0.0.1 port 9200: Connection refused' elastisearch没开启,开启之后就可以了,郁闷啊~~~
2017-12-16
共1条回复

Laravel快速开发简书

Laravel最新特性结合Mysql异步消息队列、ElasticSearch搜索引擎、Debugbar调试利器开发简书

1218 学习 · 613 问题

查看课程