<?php
namespace App\Http\Controllers;
use App\Models\PostComment;
use Illuminate\Http\Request;
class PostCommentController extends Controller
{
public function addComment(Request $request)
{
PostComment::create([
'comment' => $request->comment,
'post_id'=> $request->post_id,
'member_id' => $request->user()->id
]);
return response()->json(['message' => 'Comentário Adicionado com Sucesso'], 200);
}
public function getComments($id)
{
$comments = PostComment::query()
->join('posts', 'posts.id', '=', 'post_comments.post_id')
->join('members', 'members.id', '=', 'post_comments.member_id')
->where('post_comments.post_id', $id)
->select('post_comments.*', 'members.name as username', 'posts.id as post_id', 'members.photo')
->get();
return response()->json(['data' =>$comments], 200);
}
}