Skip to content

Commit

Permalink
#27, Code for storing the question by the student is over
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenraam committed Oct 23, 2024
1 parent e354a1e commit 035740e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
28 changes: 28 additions & 0 deletions Alumni-Project/app/Http/Controllers/ForumContoller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Http\Controllers;

use App\Models\Question;
use Illuminate\Support\Facades\Session;
use Illuminate\Http\Request;

class ForumContoller extends Controller
Expand All @@ -15,4 +17,30 @@ public function viewQuestions(){
public function createQuestion(){
return view('forum.addQuestion');
}

public function storeQuestion(Request $request)
{
// dump($request);

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

// Validate the request data
$validatedData = $request->validate([
'title' => 'required|string|max:255',
'body' => 'required|string'
]);

$question = new Question();
$question->title = $validatedData['title'];
$question->body = $validatedData['body'];

$question->student_id = $id;

$question->save();

// Redirect to the forum index page with a success message
return redirect()->route('forum.index')->with('success', 'Question added successfully.');
}


}
9 changes: 4 additions & 5 deletions Alumni-Project/resources/views/forum/addQuestion.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
<div class="tab-pane active fade show">
<ul class="nearby-contct">
<li>
<form action="" method="POST">
@csrf <!-- Include this to protect against CSRF attacks -->

<form action="{{ route('questions.store') }}" method="POST">
@csrf
<div class="form-group">
<input type="text" name="title" id="title" required>
<label for="title" class="control-label">Question Title</label>
Expand All @@ -36,12 +35,12 @@

<div class="form-group">
<textarea type="text" name="body" id="body" required></textarea>
<label for="title" class="control-label">Question Body</label>
<label for="body" class="control-label">Question Body</label>
<i class="mtrl-select"></i>
</div>

<button type="submit" class="mtr-btn"><span>Add </span></button>
</form>
</form>
</li>
</ul>
</div>
Expand Down
6 changes: 5 additions & 1 deletion Alumni-Project/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@

// View Forum
Route::get('/alumni/forum',[ForumContoller::class,'viewQuestions']);
Route::get('/alumni/forum/add',[ForumContoller::class,'createQuestion']);

// Change password
Route::get('/alumni/change-password',[AlumniLoginController::class,'showChangePasswordForm'])->name('alumni.change-password.form');
Expand Down Expand Up @@ -215,6 +214,11 @@
// View Tasks
Route::get('student/student-tasks', [TaskController::class, 'showStudentTasks'])->name('student.tasks');

// Forum
Route::get('/student/forum', [ForumContoller::class, 'viewQuestions'])->name('forum.index');
Route::get('/student/forum/add', [ForumContoller::class, 'createQuestion']);
Route::post('/student/forum/add/post', [ForumContoller::class, 'storeQuestion'])->name('questions.store');

});

// Logout route
Expand Down

0 comments on commit 035740e

Please sign in to comment.