javascript $(document).on('click', '#sidebar-user-box', function() {
var userID = $(this).attr("class");
var username = $(this).children().text() ;
if ($.inArray(userID, arr) != -1)
{
arr.splice($.inArray(userID, arr), 1);
}
arr.unshift(userID);
chatPopup = '<div class="msg_box" style="right:270px" rel="'+ userID+'">'+
'<div class="msg_head">'+username +
'<div class="close">x</div> </div>'+
'<div class="msg_wrap"><div class="msg_body" id="msg_body" ><div class="msg_push"></div></div>'+
'<div class="msg_footer"><textarea class="msg_input" id="msg_input" rows="4" style="resize:none;"></textarea></div></div></div>' ;
$("body").append( chatPopup );
displayChatBox();
});
$(document).on('keypress', 'textarea' , function(e) {
if (e.keyCode == 13 ) {
var msg = $(this).val();
$(this).val('');
if(msg.trim().length != 0){
var chatbox = $(this).parents().parents().parents().attr("rel") ;
$('<div class="msg-right">'+msg+'</div>').insertBefore('[rel="'+chatbox+'"] .msg_push');
$('.msg_body').scrollTop($('.msg_body')[0].scrollHeight);
var url= " /sendchatmessage ";
$.ajax({
headers:{'X-CSRF-token':$('meta[name=csrf-token]').attr('content')},
async:true,
type:"post",
contentType:false,
url:url,
data:msg,
processData:false,
success:function(){
console.log("success");
}
});
}
} // revision
});
контроллер public function send_chat_message(Request $req){
$name = $req->input('msg_input'); //
$newchat = new ChatMessage;
$newchat->frsender_userId = Auth::user()->user_id;
$newchat->frchat_msg = $name;
$newchat->save();
}
web. php Route::post('/sendchatmessage', 'MessengerController@send_chat_message')->name('sent-chat');