Güncelleme:
Rotalardan post edildiği parametreye göre bir güncelleme yaptım şu şekilde oldu ama yine doğruluğundan emin değilim;
// Comments
Route::post('/posts/{post}/comment', [UserCommentController::class, 'store'])->name('comment.store.post');
Route::post('/courses/{course}/comment', [UserCommentController::class, 'store'])->name('comment.store.course');
Route::post('/projects/{project}/comment', [UserCommentController::class, 'store'])->name('comment.store.project');
public function store(Request $request, $commentable)
{
if ($request->route()->parameter('post')) {
$commentable = Post::where('slug', $commentable)->firstOrFail();
} elseif ($request->route()->parameter('project')) {
$commentable = Project::where('slug', $commentable)->firstOrFail();
} elseif ($request->route()->parameter('course')) {
$commentable = Course::where('slug', $commentable)->firstOrFail();
} else {
return abort(404);
}
$commentData = new CommentData(
$request->input('body'),
get_class($commentable),
$commentable->id,
auth()->user()->id,
$request->parent_id
);
}