From d70181cf7bd3ad569cdd46e72deff70e68f06e92 Mon Sep 17 00:00:00 2001 From: Sallu9007 Date: Sun, 11 May 2025 15:42:25 +0530 Subject: [PATCH] Fix: User with same name have same folders in storage --- app/Http/Controllers/FacultyController.php | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/FacultyController.php b/app/Http/Controllers/FacultyController.php index 9b2ea2d..bb7c044 100644 --- a/app/Http/Controllers/FacultyController.php +++ b/app/Http/Controllers/FacultyController.php @@ -150,13 +150,14 @@ class FacultyController extends Controller if ($request->hasFile('proof')) { $originalName = $request->file('proof')->getClientOriginalName(); $username = auth()->user()->name; + $userId = auth()->user()->id; $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 . 'Activities-Attended'; + $folderPath = 'proofs/' . $year . '/' . $userId . '_' . $username . '/Activities-Attended'; // Store file in the specified path $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); @@ -221,13 +222,14 @@ class FacultyController extends Controller if ($request->hasFile('proof')) { $originalName = $request->file('proof')->getClientOriginalName(); $username = auth()->user()->name; + $userId = auth()->user()->id; $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 . 'Activities-Organised'; + $folderPath = 'proofs/' . $year . '/' . $userId . '_' . $username . '/Activities-Organised'; // Store file in the specified path $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); @@ -292,13 +294,14 @@ class FacultyController extends Controller if ($request->hasFile('proof')) { $originalName = $request->file('proof')->getClientOriginalName(); $username = auth()->user()->name; + $userId = auth()->user()->id; $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 . '/Iv_organised'; + $folderPath = 'proofs/' . $year . '/' . $userId . '_' . $username . '/Iv_organised'; // Store file in the specified path $proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); @@ -361,13 +364,14 @@ class FacultyController extends Controller if ($request->hasFile('paper_file')) { $originalName = $request->file('paper_file')->getClientOriginalName(); $username = auth()->user()->name; + $userId = auth()->user()->id; $fileName = $username . '_' . $originalName; // Extract year from start_date $year = date('Y', strtotime($validated['start_date'])); // Create path structure: year/faculty_name/Publications - $folderPath = 'proofs/' . $year . '/' . $username . '/Publications'; + $folderPath = 'proofs/' . $year . '/' . $userId . '_' . $username . '/Publications'; // Store file in the specified path $paperFilePath = $request->file('paper_file')->storeAs($folderPath, $fileName, 'public'); @@ -424,13 +428,14 @@ class FacultyController extends Controller if ($request->hasFile('proof_file')) { $originalName = $request->file('proof_file')->getClientOriginalName(); $username = auth()->user()->name; + $userId = auth()->user()->id; $fileName = $username . '_' . $originalName; // Extract year from start_date $year = date('Y', strtotime($validated['date_of_publication'])); // Create path structure: year/faculty_name/Publications - $folderPath = 'proofs/' . $year . '/' . $username . '/Publications'; + $folderPath = 'proofs/' . $year . '/' . $userId . '_' . $username . '/Publications'; // Store file in the specified path $proofFilePath = $request->file('proof_file')->storeAs($folderPath, $fileName, 'public'); @@ -478,13 +483,14 @@ class FacultyController extends Controller if ($request->hasFile('proof')) { $originalName = $request->file('proof')->getClientOriginalName(); $username = auth()->user()->name; + $userId = auth()->user()->id; $fileName = $username . '_' . $originalName; // Extract year from start_date $year = date('Y', strtotime($validated['start_date'])); // Create path structure: year/faculty_name/Publications - $folderPath = 'proofs/' . $year . '/' . $username . '/External Engagement'; + $folderPath = 'proofs/' . $year . '/' . $userId . '_' . $username . '/External Engagement'; // Store file in the specified path $proofFilePath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); @@ -532,13 +538,14 @@ class FacultyController extends Controller if ($request->hasFile('proof')) { $originalName = $request->file('proof')->getClientOriginalName(); $username = auth()->user()->name; + $userId = auth()->user()->id; $fileName = $username . '_' . $originalName; // Extract year from start_date $year = date('Y', strtotime($validated['start_date'])); // Create path structure: year/faculty_name/Publications - $folderPath = 'proofs/' . $year . '/' . $username . '/Online Course'; + $folderPath = 'proofs/' . $year . '/' . $userId . '_' . $username . '/Online Course'; // Store file in the specified path $proofFilePath = $request->file('proof')->storeAs($folderPath, $fileName, 'public'); @@ -587,13 +594,14 @@ class FacultyController extends Controller if ($request->hasFile('proof')) { $originalName = $request->file('proof')->getClientOriginalName(); $username = auth()->user()->name; + $userId = auth()->user()->id; $fileName = $username . '_' . $originalName; // Extract year from start_date $year = date('Y', strtotime($validated['date_of_submission'])); // Create path structure: year/faculty_name/Publications - $folderPath = 'proofs/' . $year . '/' . $username . '/Patents'; + $folderPath = 'proofs/' . $year . '/' . $userId . '_' . $username . '/Patents'; // Store file in the specified path $proofFilePath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');