use App\Entities\Projects\Comment;
use App\Entities\Projects\Project;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class CommentsController extends Controller
{
public function index(Project $project)
{
$this->authorize('view-comments', $project);
$editableComment = null;
$comments = $project->comments()->with('creator')->latest()->paginate();
if (request('action') == 'comment-edit' && request('comment_id') != null) {
$editableComment = Comment::find(request('comment_id'));
}
return view('projects.comments', compact('project', 'comments', 'editableComment'));
}
public function store(Request $request, Project $project)
{
$this->authorize('comment-on', $project);
$newComment = $request->validate([
'body' => 'required|string|max:255',
]);
$project->comments()->create([
'body' => $newComment['body'],
'creator_id' => auth()->id(),
]);
flash(__('comment.created'), 'success');
return back();
}
//
}