Skip to content

Commit

Permalink
#27, Code for adding the answer is done
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenraam committed Oct 28, 2024
1 parent 35ba36e commit a1ed206
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
19 changes: 19 additions & 0 deletions Alumni-Project/app/Http/Controllers/ForumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\Answer;
use App\Models\Question;
use Illuminate\Support\Facades\Session;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -47,5 +48,23 @@ public function storeQuestion(Request $request)
return redirect()->route('forum.index')->with('success', 'Question added successfully.');
}

public function storeAnswer(Request $req,$questionId){

$id = Session::get('user_id');

$req->validate([
'body' => 'required|string',
]);

$answer = new Answer();
$answer->answer = $req->body;
$answer->question_id = $questionId;
$answer->alumni_id = $id;

$answer->save();

return redirect()->route('question.answers', ['id' => $questionId])
->with('success', 'Your answer has been submitted.');
}

}
4 changes: 2 additions & 2 deletions Alumni-Project/resources/views/forum/viewAnswer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<p>{{ $question->body }}</p>
<hr>
@if(Auth::guard('alumni')->check())
<form action="" method="POST" class="mb-4">
<form action="{{ route('answers.store', $question->id) }}" method="POST">
@csrf
<div class="form-group">
<textarea type="text" name="body" required required></textarea>
Expand All @@ -34,11 +34,11 @@
</form>
<hr>
@endif

<li>


</li>

</ul>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions Alumni-Project/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
// View Forum
Route::get('/alumni/forum',[ForumController::class,'viewQuestions']);
Route::get('/alumni/forum/answer/{id}',[ForumController::class,'viewAnswers'])->name('question.answers');
Route::post('/alumni/forum/{id}/answer', [ForumController::class, 'storeAnswer'])->name('answers.store');

// Change password
Route::get('/alumni/change-password',[AlumniLoginController::class,'showChangePasswordForm'])->name('alumni.change-password.form');
Expand Down

0 comments on commit a1ed206

Please sign in to comment.