Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
WIKIPEDIA
/
paytekchalenge
/
app
/
Http
/
Controllers
:
PostCommentController.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?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); } }