93 lines
3.6 KiB
PHP
93 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\ActivitiesAttended;
|
|
|
|
class FacultyController extends Controller
|
|
{
|
|
// Faculty dashboard (optional)
|
|
public function index()
|
|
{
|
|
return view('faculty.dashboard');
|
|
}
|
|
|
|
// Faculty response form
|
|
public function ActivitiesAttendedForm()
|
|
{
|
|
// Logic to show the response form
|
|
return view('faculty.activities-attended-form');
|
|
}
|
|
|
|
public function ActivitiesAttendedFormResponse(Request $request)
|
|
{
|
|
// dd($request->all());
|
|
try {
|
|
// Validate the request data
|
|
$validated = $request->validate([
|
|
'title' => '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',
|
|
'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
|
|
// Handle the file upload
|
|
$proofPath = null;
|
|
if ($request->hasFile('proof')) {
|
|
$originalName = $request->file('proof')->getClientOriginalName();
|
|
$username = auth()->user()->name;
|
|
$fileName = $username . '_' . $originalName;
|
|
|
|
// Extract year from start_date
|
|
$year = date('Y', strtotime($validated['start_date']));
|
|
|
|
// Create path structure: year/faculty_name
|
|
$folderPath = 'proofs/' . $year . '/' . $username;
|
|
|
|
// Store file in the specified path
|
|
$proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');
|
|
}
|
|
|
|
// Save the response to the database
|
|
// dd($validated['organising_institute']);
|
|
ActivitiesAttended::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'],
|
|
'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());
|
|
}
|
|
}
|
|
}
|