From ec028d3f6f6ac52f603b3b16b2c0bedc132a586c Mon Sep 17 00:00:00 2001 From: Sallu9007 Date: Sun, 26 Jan 2025 02:13:19 +0530 Subject: [PATCH] Feat: Responses form --- app/Http/Controllers/FacultyController.php | 41 ++++++++--- app/Models/Response.php | 26 +++++++ ...25_01_25_201943_create_responses_table.php | 29 ++++++++ .../views/faculty/response-form.blade.php | 71 +++++++++++++++++++ 4 files changed, 156 insertions(+), 11 deletions(-) create mode 100644 app/Models/Response.php create mode 100644 database/migrations/2025_01_25_201943_create_responses_table.php diff --git a/app/Http/Controllers/FacultyController.php b/app/Http/Controllers/FacultyController.php index a062bec..83cc97a 100644 --- a/app/Http/Controllers/FacultyController.php +++ b/app/Http/Controllers/FacultyController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\Models\Response; class FacultyController extends Controller { @@ -22,18 +23,36 @@ class FacultyController extends Controller // Handle form submission from faculty public function submitResponse(Request $request) { - // Validate and handle the form submission - $validated = $request->validate([ - 'response' => 'required|string', - ]); + try { + // Validate the request data + $validated = $request->validate([ + 'title' => 'required|string', + 'activity_type' => 'required|string', + 'start_date' => 'required|date', + 'end_date' => 'required|date', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx', // Validate proof file + ]); - // Save the response, perhaps to a 'responses' table - // Response::create([ - // 'faculty_id' => auth()->user()->id, - // 'response' => $validated['response'], - // ]); + // Handle the file upload + $proofPath = null; + if ($request->hasFile('proof')) { + $proofPath = $request->file('proof')->store('proofs', 'public'); + } - // Redirect or return a success message - return redirect()->route('faculty.dashboard')->with('status', 'Response submitted successfully'); + // Save the response to the database + Response::create([ + 'title' => $validated['title'], + 'activity_type' => $validated['activity_type'], + 'start_date' => $validated['start_date'], + 'end_date' => $validated['end_date'], + 'proof' => $proofPath, // Store the file path + 'faculty_id' => auth()->user()->id, // Assuming the logged-in user is the faculty + ]); + + return redirect()->route('faculty.dashboard')->with('status', 'Response submitted successfully'); + } catch (\Exception $e) { + // Dump the error and stop execution for debugging + dd($e->getMessage()); + } } } diff --git a/app/Models/Response.php b/app/Models/Response.php new file mode 100644 index 0000000..6bd2ac0 --- /dev/null +++ b/app/Models/Response.php @@ -0,0 +1,26 @@ +belongsTo(User::class, 'faculty_id'); + } +} diff --git a/database/migrations/2025_01_25_201943_create_responses_table.php b/database/migrations/2025_01_25_201943_create_responses_table.php new file mode 100644 index 0000000..40b877d --- /dev/null +++ b/database/migrations/2025_01_25_201943_create_responses_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('title'); + $table->string('activity_type'); + $table->date('start_date'); + $table->date('end_date'); + $table->string('proof')->nullable(); + $table->unsignedBigInteger('faculty_id'); // Ensure it is unsignedBigInteger + $table->foreign('faculty_id')->references('id')->on('users')->onDelete('cascade'); // Add the foreign key constraint + $table->timestamps(); + }); +} + + + public function down() + { + Schema::dropIfExists('responses'); + } +} diff --git a/resources/views/faculty/response-form.blade.php b/resources/views/faculty/response-form.blade.php index e69de29..ccb7472 100644 --- a/resources/views/faculty/response-form.blade.php +++ b/resources/views/faculty/response-form.blade.php @@ -0,0 +1,71 @@ +@extends('layouts.app') + +@section('content') +
+
+
+

+ Submit Activity Response +

+

+ Fill in the details of the activity you participated in. +

+
+
+
+ @csrf +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+
+
+ + +
+ +
+
+
+
+
+@endsection