I've opened this discussion . I have the same code that is there, please have a look at that.
I'm getting the comment
body on the fly, perfectly fine, But Now I want to fetch the user name
and image
when the user leaves a comment and show it on the screen below the post description.
Problem
Right now I can get only the user_id
, how can I get the user_name
and the image?
My comments table where I'm inserting the comments looks like:.
So how can I get the user_name
of the user who is leaving a comment, right now I can only get the user_id
For better understanding, I want to get the user_name
below this line in Ajax Request Code
$(".show_comments_"+post_id).append("<div style = 'color:red;'>"+data.msg+"</div>")
You can see I've tried for the name, but I'm unable to get the user_name
and image
who is leaving a comment.
Note:
I've models
that have the perfectly fine relations from posts
to users
and vice versa.
I'm new to laravel.
Updated :
In Ajax handling Controller
I have code something like this :
public function storeComments(Request $request,Comment $body,$post_id){
if($request->ajax()){
$comment = new Comment;
$comment->user_id = Auth::user()->id;
$comment->post_id = $post_id;
$comment->body = Input::get('body');
$comment->save();
return response()->json( ['msg'=>$comment->body,'user_id' =>$comment->user_id] );
}
}
I'm trying to load image but I got the following
this is what I got instead of image
Thanks In advance.