Merhabalar

Laravel ile proje yaptım. Bir kaç aşama kaldı. Ajax ile yorum sistemim var ve sorunsuzca çalışıyor. Yorumu ajax ile gönderiyor fakat gönderdikten sonra sadece bir uyarı getiriyor json ile. İstediğim şey ajax ile yorum yaptıktan sonra bu yorumları gönen cevaba göre getirmesi. yani div load gibi bi şey yaptırmak istiyorum sisteme. Yardımcı olabilirseniz sevinirim.



Blade HTML Yorum şablonu:





Bu Konuya Toplam {{ $posts->comments()->count() }} Yorum Yapıldı






    @foreach ($posts->comments as $comment)











  • {{$comment->user->statu}} - {{$comment->user->name}}





    {!! $comment->user->star !!}





    {{$comment->comment}}






  • @endforeach








Controller Kodu:


public function store(Request $request)
{
//
if(Auth::guard('student')->user())
{

$request->validate([
'comment' => 'required|min:3|max:300|regex:/^([0-9\p{Latin}]+[\ \-]?)+[a-zA-Z0-9]+$/u'
]);

$comment = new Comment();
$comment->post_id = $request->id;
$comment->user_id = Auth::guard('student')->user()->id;
$comment->comment = $request->comment;
$comment->status = 1;


if($comment->save()){

return response()->json(['yes' => 'asdasdasd']);

}else{

return response()->json(['no' => 'asdasdasdasd']);

}

}else{
return abort(404);
}
}



Ajax Kodu:


$(document).ready(function(){
$('#send_form').click(function(e){
e.preventDefault();
/*Ajax Request Header setup*/
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});

$('#send_form').html('Gönderiliyor..');


/* Submit form data using ajax*/
$.ajax({
url: "{{ url('/comment/send')}}",
method: 'post',
data: $('#contact_us').serialize(),
success: function(response){
//------------------------
$('#send_form').html('Yorum Yap');
$('#res_message').show();
$('#res_message').html(response.msg);
$('#msg_div').removeClass('d-none');

document.getElementById("contact_us").reset();
setTimeout(function(){
$('#res_message').hide();
$('#msg_div').hide();
},10000);
//--------------------------
}});
});
});