validate([ 'question' => 'required|string|max:2000', ]); LessonQuestion::create([ 'lesson_id' => $lesson->id, 'user_id' => Auth::id(), 'question' => $request->question, 'published' => 0, ]); return back()->with('success', 'Your question has been submitted.'); } /** * Optional — allow teachers (or admins) to post an answer. */ public function answer(Request $request, LessonQuestion $question) { $request->validate([ 'answer' => 'required|string|max:5000', ]); $question->update([ 'answer' => $request->answer, 'answered_by' => Auth::id(), 'answered_at' => now(), ]); return back()->with('success', 'Answer posted successfully.'); } }