diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index e1b7cde..deda09b 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -23,18 +23,35 @@ class AdminController extends Controller } public function getResponses() - { - $responses = Response::with('user'); +{ + $responses = Response::with('user', 'department'); - return DataTables::of($responses) - ->addColumn('user_name', function ($response) { - return $response->user->name ?? 'Unknown'; - }) - ->addColumn('action', function ($response) { - $viewButton = $response->proof ? 'View' : 'No Proof'; - return $viewButton; - }) - ->rawColumns(['action']) - ->make(true); - } + return DataTables::of($responses) + ->addColumn('user_name', function ($response) { + return $response->user->name ?? 'Unknown'; + }) + ->addColumn('department_name', function ($response) { + return $response->department->name ?? 'Unknown'; + }) + ->addColumn('start_date', function ($response) { + return \Carbon\Carbon::parse($response->start_date)->format('d-m-Y'); + }) + ->addColumn('start_time', function ($response) { + return \Carbon\Carbon::parse($response->start_date)->format('h:i A'); + }) + ->addColumn('end_date', function ($response) { + return \Carbon\Carbon::parse($response->end_date)->format('d-m-Y'); + }) + ->addColumn('end_time', function ($response) { + return \Carbon\Carbon::parse($response->end_date)->format('h:i A'); + }) + ->addColumn('action', function ($response) { + $viewButton = $response->proof + ? 'View' + : 'No Proof'; + return $viewButton; + }) + ->rawColumns(['action']) + ->make(true); +} } diff --git a/app/Http/Controllers/FacultyController.php b/app/Http/Controllers/FacultyController.php index feba68b..20d3746 100644 --- a/app/Http/Controllers/FacultyController.php +++ b/app/Http/Controllers/FacultyController.php @@ -20,19 +20,32 @@ class FacultyController extends Controller return view('faculty.response-form'); } - // Handle form submission from faculty public function submitResponse(Request $request) { + // dd($request->all()); try { // Validate the request data $validated = $request->validate([ 'title' => 'required|string', - 'activity_type' => 'required|string', + 'organising_institute' => 'required|string', + 'address' => 'required|string', + // 'department' => 'required|string', + // 'faculty_name' => 'required|string', 'start_date' => 'required|date', + 'start_time' => 'required|date_format:H:i', 'end_date' => 'required|date', - 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx', // Validate proof file + 'end_time' => 'required|date_format:H:i', + 'num_days' => 'required|integer', + 'activity_type' => 'required|string', + 'category' => 'required|string', + 'level' => 'required|string', + 'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip', ]); + // Combine start date and time + $startDateTime = date('Y-m-d H:i:s', strtotime("{$validated['start_date']} {$validated['start_time']}")); + $endDateTime = date('Y-m-d H:i:s', strtotime("{$validated['end_date']} {$validated['end_time']}")); + // Handle the file upload $proofPath = null; if ($request->hasFile('proof')) { @@ -43,18 +56,27 @@ class FacultyController extends Controller } // Save the response to the database + // dd($validated['organising_institute']); Response::create([ 'title' => $validated['title'], + 'organising_institute' => $validated['organising_institute'], + 'address' => $validated['address'], + 'department_id' => auth()->user()->department->id, + 'faculty_id' => auth()->user()->id, + // 'faculty_name' => $validated['faculty_name'], + 'start_date' => $startDateTime, + 'end_date' => $endDateTime, + 'num_days' => $validated['num_days'], '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 + 'category' => $validated['category'], + 'level' => $validated['level'], + 'proof' => $proofPath, ]); return redirect()->route('faculty.dashboard')->with('status', 'Response submitted successfully'); } catch (\Exception $e) { // Handle the exception and provide an error message + // dd($e); return back()->withErrors('An error occurred while submitting your response: ' . $e->getMessage()); } } diff --git a/app/Models/Response.php b/app/Models/Response.php index 6bd2ac0..c46fa5a 100644 --- a/app/Models/Response.php +++ b/app/Models/Response.php @@ -11,14 +11,25 @@ class Response extends Model protected $fillable = [ 'title', - 'activity_type', + 'organising_institute', + 'address', + 'department_id', + 'faculty_id', 'start_date', 'end_date', + 'num_days', + 'activity_type', + 'category', + 'level', 'proof', - 'faculty_id', ]; + // Define the relationship to the User (Faculty) + public function department() + { + return $this->belongsTo(Department::class, 'department_id'); + } public function user() { return $this->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 index 40b877d..1c4effa 100644 --- a/database/migrations/2025_01_25_201943_create_responses_table.php +++ b/database/migrations/2025_01_25_201943_create_responses_table.php @@ -6,20 +6,29 @@ use Illuminate\Support\Facades\Schema; class CreateResponsesTable extends Migration { + + // Updated Migration public function up() -{ - Schema::create('responses', function (Blueprint $table) { - $table->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(); - }); -} + { + Schema::create('responses', function (Blueprint $table) { + $table->id(); + $table->string('title'); + $table->string('organising_institute'); + $table->text('address'); + $table->unsignedBigInteger('department_id'); + $table->unsignedBigInteger('faculty_id'); + $table->dateTime('start_date'); + $table->dateTime('end_date'); + $table->integer('num_days'); + $table->string('activity_type'); + $table->string('category'); + $table->string('level'); + $table->string('proof')->nullable(); + $table->foreign('faculty_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('department_id')->references('id')->on('departments')->onDelete('cascade'); + $table->timestamps(); + }); + } public function down() diff --git a/resources/views/admin/responses.blade.php b/resources/views/admin/responses.blade.php index 0a17c67..43fa466 100644 --- a/resources/views/admin/responses.blade.php +++ b/resources/views/admin/responses.blade.php @@ -9,22 +9,32 @@
-
- + +
+
+ - - - + + + + + + + + + + + +
ID TitleActivity TypeStart DateEnd DateOrganising InstituteAddressDepartment FacultyStart DateEnd DateNum DaysActivity TypeCategoryLevel Proof
-
@@ -33,12 +43,30 @@ @section('scripts') + + + + + + + + diff --git a/resources/views/faculty/response-form.blade.php b/resources/views/faculty/response-form.blade.php index ccb7472..83f012c 100644 --- a/resources/views/faculty/response-form.blade.php +++ b/resources/views/faculty/response-form.blade.php @@ -15,57 +15,120 @@
@csrf
-
- -
- -
- +
+ + +
+ + +
+ +
+ + +
+
+ + +
+ +
+
+ + +
+
+ +
- -
- -
- + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ +
- -
- -
- + +
+
+ +
-
- - -
- -
- +
+ +
-
- - -
- -
- +
+ + +
+
+ +
-
-
+
-@endsection + + +@endsection \ No newline at end of file