updated profile setting page

Cette révision appartient à :
Ibrahim Khail Shakil 2023-12-09 13:50:56 +06:00
Parent 914f4ceb36
révision addbb796bd
4 fichiers modifiés avec 54 ajouts et 8 suppressions

Voir le fichier

@ -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.');
}
}
} }

Fichier binaire non affiché.

Après

Largeur:  |  Hauteur:  |  Taille: 70 KiB

Voir le fichier

@ -926,13 +926,15 @@ class="purchase-area-items-start mb-0 d-flex align-items-lg-center flex-column f
<div class="white-bg"> <div class="white-bg">
<div class="change-image-wizard"> <div class="change-image-wizard">
<div class="image mx-auto"> <div class="image mx-auto">
<img src="{{asset('public/frontend/dist/images/user/user-img-01.jpg')}}" <img src="{{ asset('public/uploads/students/' . $student_info->image) }}" alt="User" height="200" width="200">
alt="User" />
</div> </div>
<form action="#"> <form id="changeImageForm" action="{{ route('change_image') }}" method="post"
enctype="multipart/form-data">
@csrf
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
<button type="submit" class="button button--primary-outline">CHANGE <input type="file" name="image" id="newImageInput">
iMAGE</button> <button type="button" id="changeImageButton"
class="button button--primary-outline">CHANGE IMAGE</button>
</div> </div>
</form> </form>
<p>Image size should be under 1MB image ratio 200px.</p> <p>Image size should be under 1MB image ratio 200px.</p>
@ -949,3 +951,23 @@ class="purchase-area-items-start mb-0 d-flex align-items-lg-center flex-column f
</section> </section>
@endsection @endsection
@push('scripts')
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
$(document).ready(function() {
// Hide the file input initially
$('#newImageInput').hide();
// Trigger the file input when the button is clicked
$('#changeImageButton').click(function() {
$('#newImageInput').click();
});
// Automatically submit the form when a file is selected
$('#newImageInput').change(function() {
$('#changeImageForm').submit();
});
});
</script>
@endpush

Voir le fichier

@ -80,6 +80,8 @@
Route::get('/dashboard', [studashboard::class, 'index'])->name('studentdashboard'); Route::get('/dashboard', [studashboard::class, 'index'])->name('studentdashboard');
Route::get('/profile', [stu_profile::class, 'index'])->name('student_profile'); 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('/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 () { Route::get('/watchCourse', function () {
return view('frontend.watchCourse'); return view('frontend.watchCourse');
@ -137,4 +139,3 @@
Route::get('add-to-cart/{id}', [CartController::class, 'addToCart'])->name('add.to.cart'); Route::get('add-to-cart/{id}', [CartController::class, 'addToCart'])->name('add.to.cart');
Route::patch('update-cart', [CartController::class, 'update'])->name('update.cart'); Route::patch('update-cart', [CartController::class, 'update'])->name('update.cart');
Route::delete('remove-from-cart', [CartController::class, 'remove'])->name('remove.from.cart'); Route::delete('remove-from-cart', [CartController::class, 'remove'])->name('remove.from.cart');