Feat: Responses form
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Response;
|
||||||
|
|
||||||
class FacultyController extends Controller
|
class FacultyController extends Controller
|
||||||
{
|
{
|
||||||
@@ -22,18 +23,36 @@ class FacultyController extends Controller
|
|||||||
// Handle form submission from faculty
|
// Handle form submission from faculty
|
||||||
public function submitResponse(Request $request)
|
public function submitResponse(Request $request)
|
||||||
{
|
{
|
||||||
// Validate and handle the form submission
|
try {
|
||||||
$validated = $request->validate([
|
// Validate the request data
|
||||||
'response' => 'required|string',
|
$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
|
// Handle the file upload
|
||||||
// Response::create([
|
$proofPath = null;
|
||||||
// 'faculty_id' => auth()->user()->id,
|
if ($request->hasFile('proof')) {
|
||||||
// 'response' => $validated['response'],
|
$proofPath = $request->file('proof')->store('proofs', 'public');
|
||||||
// ]);
|
}
|
||||||
|
|
||||||
// Redirect or return a success message
|
// Save the response to the database
|
||||||
return redirect()->route('faculty.dashboard')->with('status', 'Response submitted successfully');
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
app/Models/Response.php
Normal file
26
app/Models/Response.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Response extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'title',
|
||||||
|
'activity_type',
|
||||||
|
'start_date',
|
||||||
|
'end_date',
|
||||||
|
'proof',
|
||||||
|
'faculty_id',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Define the relationship to the User (Faculty)
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'faculty_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateResponsesTable extends 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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('responses');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||||
|
<div class="bg-white overflow-hidden shadow sm:rounded-lg">
|
||||||
|
<div class="px-4 py-5 sm:px-6">
|
||||||
|
<h3 class="text-lg leading-6 font-medium text-gray-900">
|
||||||
|
Submit Activity Response
|
||||||
|
</h3>
|
||||||
|
<p class="mt-1 max-w-2xl text-sm text-gray-500">
|
||||||
|
Fill in the details of the activity you participated in.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="border-t border-gray-200">
|
||||||
|
<form method="POST" action="{{ route('faculty.submitResponse') }}" enctype="multipart/form-data">
|
||||||
|
@csrf
|
||||||
|
<div class="px-4 py-5 sm:px-6">
|
||||||
|
<div class="space-y-4">
|
||||||
|
<!-- Title of Activity -->
|
||||||
|
<div class="flex items-center">
|
||||||
|
<label for="title" class="block text-sm font-medium text-gray-700">Title of Activity</label>
|
||||||
|
<div class="mt-1">
|
||||||
|
<input type="text" name="title" id="title" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Type of Activity -->
|
||||||
|
<div class="flex items-center">
|
||||||
|
<label for="activity_type" class="block text-sm font-medium text-gray-700">Type of Activity</label>
|
||||||
|
<div class="mt-1">
|
||||||
|
<input type="text" name="activity_type" id="activity_type" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Start Date -->
|
||||||
|
<div class="flex items-center">
|
||||||
|
<label for="start_date" class="block text-sm font-medium text-gray-700">Start Date</label>
|
||||||
|
<div class="mt-1">
|
||||||
|
<input type="date" name="start_date" id="start_date" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- End Date -->
|
||||||
|
<div class="flex items-center">
|
||||||
|
<label for="end_date" class="block text-sm font-medium text-gray-700">End Date</label>
|
||||||
|
<div class="mt-1">
|
||||||
|
<input type="date" name="end_date" id="end_date" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Proof of Activity -->
|
||||||
|
<div class="flex items-center">
|
||||||
|
<label for="proof" class="block text-sm font-medium text-gray-700">Proof of Activity</label>
|
||||||
|
<div class="mt-1">
|
||||||
|
<input type="file" name="proof" id="proof" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" accept=".jpg,.jpeg,.png,.pdf,.doc,.docx">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Submit Button -->
|
||||||
|
<div class="px-4 py-3 sm:px-6 text-right">
|
||||||
|
<button type="submit" class="inline-flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
|
||||||
|
Submit Response
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|||||||
Reference in New Issue
Block a user