文章审核,数据库已经更新了,但是网页不更新,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(); } }); });
012017-12-16
相似问题