Я пытаюсь обновить значение столбца, но теперь он работает.Я пытаюсь это обновить представления на странице, но это не происходит.Нет ошибки Все еще не обновляется в базе данных.Просмотр страницы
<form style="" name="fbCommentCountform" id="fbCommentCountForm" action="{{ url('/posts/{$display_post->id}')}}" method="POST">
{{ csrf_field() }}
<input type="hidden" name="_method" value="PUT">
<input type="text" name="commentCount" id="fbFormCommentCount">
<input type="text" name="visitCount" id="hiddenFormPostVisitCounter" value="{{ $display_post->visit_count }}">
</form>
Контроллер
public function update(Request $request, $id)
{
$image = $request->file('featured_img');
$posts = Post::findOrFail($id);
if(!empty($image))
{
$name = str_slug($request->title).'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('/public/images');
$imagePath = $destinationPath. "/". $name;
$image->move($destinationPath, $name);
$posts->featured_img = $name;
}
$posts->title = $request->title;
$posts->body = $request->body;
$posts->slug = $request->slug;
$posts->categories_id = $request->category;
$posts->description = $request->description;
$posts->visit_count = $request->visitCount;
$this->validate($request,[
'title' => 'required|string|max:255',
'body' => 'required'
]);
$posts->update();
return redirect('posts');
Теперь вот код ajax
<script>
let fbCommentCount = document.getElementById('fbCommentCount').getElementsByClassName('fb_comments_count');
setTimeout(function() {
document.getElementById('fbFormCommentCount').value = fbCommentCount[0].innerHTML;
var $formVar = $('#fbCommentCountForm');
let visitCount = document.getElementById('hiddenFormPostVisitCounter').value;
let visitCountPlusOne = parseInt(visitCount) + 1;
document.getElementById('hiddenFormPostVisitCounter').value = visitCountPlusOne;
$.ajax({
url: $formVar.prop('{{ url('/posts/{$display_post->id}') }}'),
method: 'PUT',
data: $formVar.serialize(),
});
}, 1000);
</script>
Если кто-то может помочь мне решить эту проблему