45 lines
1.0 KiB
PHP
45 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\CommentRequest;
|
|
use App\Models\Comment;
|
|
use App\Models\Deal;
|
|
|
|
class CommentController extends Controller
|
|
{
|
|
public function index(Deal $deal)
|
|
{
|
|
$comments = $deal->comments()->with('user')->latest()->get();
|
|
$html = view('components.dashboard.user.deal-comment.index', compact('comments'))->render();
|
|
|
|
return response()->json(['html' => $html]);
|
|
}
|
|
|
|
public function store(Deal $deal, CommentRequest $request)
|
|
{
|
|
$data = $request->validated();
|
|
$data['user_id'] = $request->user()->id;
|
|
$data['deal_id'] = $deal->id;
|
|
|
|
Comment::create($data);
|
|
|
|
return response()->json(['message' => 'Comment created successfully.'], 201);
|
|
}
|
|
|
|
public function show(Comment $comment) {}
|
|
|
|
public function update(CommentRequest $request, Comment $comment)
|
|
{
|
|
$comment->update($request->validated());
|
|
|
|
}
|
|
|
|
public function destroy(Comment $comment)
|
|
{
|
|
$comment->delete();
|
|
|
|
return response()->json();
|
|
}
|
|
}
|