Feat: Save files in storae with original name and user name

This commit is contained in:
Sallu9007
2025-01-26 20:59:55 +05:30
parent dac2090e5c
commit d3e046c6a2

View File

@@ -36,7 +36,10 @@ class FacultyController extends Controller
// Handle the file upload // Handle the file upload
$proofPath = null; $proofPath = null;
if ($request->hasFile('proof')) { 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 // Save the response to the database
@@ -51,8 +54,8 @@ class FacultyController extends Controller
return redirect()->route('faculty.dashboard')->with('status', 'Response submitted successfully'); return redirect()->route('faculty.dashboard')->with('status', 'Response submitted successfully');
} catch (\Exception $e) { } catch (\Exception $e) {
// Dump the error and stop execution for debugging // Handle the exception and provide an error message
dd($e->getMessage()); return back()->withErrors('An error occurred while submitting your response: ' . $e->getMessage());
} }
} }
} }