diff --git a/app/Http/Controllers/Students/ProfileController.php b/app/Http/Controllers/Students/ProfileController.php index 61033a2..7697460 100644 --- a/app/Http/Controllers/Students/ProfileController.php +++ b/app/Http/Controllers/Students/ProfileController.php @@ -57,4 +57,27 @@ public function setSession($student) ] ); } + + // ProfileController.php + public function changeImage(Request $request) + { + try { + $user = Student::find(currentUserId()); + + if ($request->hasFile('image')) { + $imageName = rand(111, 999) . time() . '.' . $request->image->extension(); + $request->image->move(public_path('uploads/students'), $imageName); + $user->image = $imageName; + $user->save(); + + return redirect()->back()->with('success', 'Image changed successfully.'); + } else { + return redirect()->back()->with('error', 'Please select a valid image file.'); + } + } catch (\Exception $e) { + // dd($e); + return redirect()->back()->with('error', 'An error occurred. Please try again.'); + } + } + } diff --git a/public/uploads/students/8841702108048.jpg b/public/uploads/students/8841702108048.jpg new file mode 100644 index 0000000..a45ae41 Binary files /dev/null and b/public/uploads/students/8841702108048.jpg differ diff --git a/resources/views/students/profile.blade.php b/resources/views/students/profile.blade.php index 7298634..88b3d5f 100644 --- a/resources/views/students/profile.blade.php +++ b/resources/views/students/profile.blade.php @@ -926,13 +926,15 @@ class="purchase-area-items-start mb-0 d-flex align-items-lg-center flex-column f
+ Image size should be under 1MB image ratio 200px.
@@ -948,4 +950,24 @@ class="purchase-area-items-start mb-0 d-flex align-items-lg-center flex-column f