From d3e046c6a2a35202629f896d5a733f95c3030daa Mon Sep 17 00:00:00 2001 From: Sallu9007 Date: Sun, 26 Jan 2025 20:59:55 +0530 Subject: [PATCH] Feat: Save files in storae with original name and user name --- app/Http/Controllers/FacultyController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/FacultyController.php b/app/Http/Controllers/FacultyController.php index 83cc97a..feba68b 100644 --- a/app/Http/Controllers/FacultyController.php +++ b/app/Http/Controllers/FacultyController.php @@ -36,7 +36,10 @@ class FacultyController extends Controller // Handle the file upload $proofPath = null; if ($request->hasFile('proof')) { - $proofPath = $request->file('proof')->store('proofs', 'public'); + $originalName = $request->file('proof')->getClientOriginalName(); + $username = auth()->user()->name; + $fileName = $username . '_' . $originalName; + $proofPath = $request->file('proof')->storeAs('proofs', $fileName, 'public'); } // Save the response to the database @@ -51,8 +54,8 @@ class FacultyController extends Controller return redirect()->route('faculty.dashboard')->with('status', 'Response submitted successfully'); } catch (\Exception $e) { - // Dump the error and stop execution for debugging - dd($e->getMessage()); + // Handle the exception and provide an error message + return back()->withErrors('An error occurred while submitting your response: ' . $e->getMessage()); } } }