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
- User + User
-
+ + @csrf
- + +

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
-@endsection \ No newline at end of file +@endsection + +@push('scripts') + + +@endpush \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 2052214..2f2b195 100644 --- a/routes/web.php +++ b/routes/web.php @@ -42,7 +42,7 @@ Route::get('/login', [auth::class, 'signInForm'])->name('login'); Route::post('/login', [auth::class, 'signInCheck'])->name('login.check'); Route::get('/logout', [auth::class, 'signOut'])->name('logOut'); - + Route::middleware(['checkauth'])->prefix('admin')->group(function () { Route::get('/dashboard', [dashboard::class, 'index'])->name('dashboard'); @@ -80,6 +80,8 @@ Route::get('/dashboard', [studashboard::class, 'index'])->name('studentdashboard'); Route::get('/profile', [stu_profile::class, 'index'])->name('student_profile'); Route::post('/profile/save', [stu_profile::class, 'save_profile'])->name('student_save_profile'); + Route::post('/change-image', [stu_profile::class, 'changeImage'])->name('change_image'); + Route::get('/watchCourse', function () { return view('frontend.watchCourse'); @@ -137,4 +139,3 @@ Route::get('add-to-cart/{id}', [CartController::class, 'addToCart'])->name('add.to.cart'); Route::patch('update-cart', [CartController::class, 'update'])->name('update.cart'); Route::delete('remove-from-cart', [CartController::class, 'remove'])->name('remove.from.cart'); -