diff --git a/app/Http/Controllers/Account/EditProfileController.php b/app/Http/Controllers/Account/EditProfileController.php index 49d9fd8..d0668f6 100644 --- a/app/Http/Controllers/Account/EditProfileController.php +++ b/app/Http/Controllers/Account/EditProfileController.php @@ -6,10 +6,14 @@ use App\Http\Controllers\Controller; use App\Http\Requests\Account\EditProfileChangePasswordRequest; use App\Http\Requests\Account\EditProfileUpdateRequest; use App\Models\City; +use App\Models\File; use App\Models\Province; +use App\Models\UserAvatar; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Log; class EditProfileController extends Controller { @@ -24,23 +28,67 @@ class EditProfileController extends Controller if ($selectedProvinceId) { $cities = City::where('province_id', $selectedProvinceId)->orderBy('name')->get(); } - return view('account.edit-profile', compact('title','user', 'provinces' , 'cities')); + return view('account.edit-profile', compact('title', 'user', 'provinces', 'cities')); } public function update(EditProfileUpdateRequest $request) { - $inputs = $request->only([ - 'first_name', - 'last_name', - 'email', - 'mobile', - 'city_id', - 'province_id', - ]); + $data = $request->validated(); + $user = Auth::user(); - Auth::user()->update($inputs); + DB::beginTransaction(); - return redirect()->back()->with('success', 'پروفایل با موفقیت ویرایش شد.'); + try { + + $user->update([ + 'first_name' => $data['first_name'], + 'last_name' => $data['last_name'], + 'email' => $data['email'], + 'mobile' => $data['mobile'], + 'province_id' => $data['province_id'] ?? null, + 'city_id' => $data['city_id'] ?? null, + ]); + + if ($request->hasFile('avatar')) { + $avatarFile = $request->file('avatar'); + $imageName = $user->id . '_' . time() . rand(11111, 99999) . '.' . $avatarFile->extension(); + + $oldAvatar = UserAvatar::where('user_id', $user->id)->first(); + + if ($oldAvatar) { + $oldFile = File::find($oldAvatar->file_id); + deleteFile($oldFile); + $oldAvatar->delete(); + } + + $path = $avatarFile->storeAs('avatars', $imageName, 'public'); + + $file = File::create([ + 'name' => $avatarFile->getClientOriginalName(), + 'original_name' => $avatarFile->getClientOriginalName(), + 'size' => $avatarFile->getSize(), + 'extension' => $avatarFile->extension(), + 'path' => $path + ]); + + + UserAvatar::create([ + 'user_id' => $user->id, + 'file_id' => $file->id, + ]); + } + + DB::commit(); + + return redirect()->back()->with('success', 'پروفایل با موفقیت ویرایش شد.'); + } catch (\Exception $exception) { + Log::error($exception); + DB::rollBack(); + + return redirect()->back() + ->withInput() + ->with('error', 'خطایی در ویرایش پروفایل رخ داد. لطفاً دوباره تلاش کنید.'); + } } public function changePassword(EditProfileChangePasswordRequest $request) diff --git a/app/Http/Requests/Account/EditProfileUpdateRequest.php b/app/Http/Requests/Account/EditProfileUpdateRequest.php index c41176d..24e069c 100644 --- a/app/Http/Requests/Account/EditProfileUpdateRequest.php +++ b/app/Http/Requests/Account/EditProfileUpdateRequest.php @@ -54,6 +54,12 @@ class EditProfileUpdateRequest extends FormRequest 'nullable', 'exists:cities,id' ], + 'avatar' => [ + 'nullable', + 'image', + 'mimes:jpeg,png,jpg,webp', + 'max:800' + ] ]; } diff --git a/resources/views/account/edit-profile.blade.php b/resources/views/account/edit-profile.blade.php index 8649f1f..319a9b8 100644 --- a/resources/views/account/edit-profile.blade.php +++ b/resources/views/account/edit-profile.blade.php @@ -20,7 +20,7 @@

بروزرسانی مشخصات پروفایل

-
+ @csrf
@@ -98,6 +98,15 @@ @enderror
+
+
+ + + @error('avatar') + {{ $message }} + @enderror +
+
- + @if(auth()->user()->avatar?->file) + img + @else + img + @endif

{{auth()->user()->first_name . ' ' . auth()->user()->last_name}}

diff --git a/storage/framework/views/0b002217e2108a54974ba03c50e8941a.php b/storage/framework/views/0b002217e2108a54974ba03c50e8941a.php new file mode 100644 index 0000000..f69a06d --- /dev/null +++ b/storage/framework/views/0b002217e2108a54974ba03c50e8941a.php @@ -0,0 +1,29 @@ + +
+
+ +

user()->first_name . ' ' . auth()->user()->last_name); ?>

+
+ +
+ + \ No newline at end of file diff --git a/storage/framework/views/1a86b579c48f772630a544f2f581551d.php b/storage/framework/views/1a86b579c48f772630a544f2f581551d.php index 25ccd7a..623bc96 100644 --- a/storage/framework/views/1a86b579c48f772630a544f2f581551d.php +++ b/storage/framework/views/1a86b579c48f772630a544f2f581551d.php @@ -57,10 +57,29 @@ اکنون ثبت کن - - - افزودن به علاقه مندی ها - + + guard()->check()): ?> + + + + + + + + + افزودن به علاقه‌مندی‌ها + + diff --git a/storage/framework/views/2ce8a569e97b29ca18caf424a682993d.php b/storage/framework/views/2ce8a569e97b29ca18caf424a682993d.php new file mode 100644 index 0000000..a0b5332 --- /dev/null +++ b/storage/framework/views/2ce8a569e97b29ca18caf424a682993d.php @@ -0,0 +1,27 @@ +startSection('account-content'); ?> +
+
+ +
+
+
    +
  • اسم کامل : first_name . ' ' . $user->last_name); ?>
  • +
  • ایمیل: + + + email); ?> + + + +
  • +
  • شماره: mobile); ?>
  • +
  • تاریخ عضویت: created_at->toJalali()->format('Y-m-d')); ?>
  • +
+
+
+
+
+stopSection(); ?> + +make('account.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?> \ No newline at end of file diff --git a/storage/framework/views/6a8a787033eeee23e8dbf36023573a13.php b/storage/framework/views/6a8a787033eeee23e8dbf36023573a13.php new file mode 100644 index 0000000..5d0aee0 --- /dev/null +++ b/storage/framework/views/6a8a787033eeee23e8dbf36023573a13.php @@ -0,0 +1,32 @@ +startSection('content'); ?> +
+ + +
+
+
+
+ make('account.layouts.sidebar', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?> +
+
+ yieldContent('account-content'); ?> +
+
+
+
+ +
+ +stopSection(); ?> + + + +make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?> \ No newline at end of file diff --git a/storage/framework/views/7cc807de2c2a5b154e91d26d3ce81c15.php b/storage/framework/views/7cc807de2c2a5b154e91d26d3ce81c15.php index f3452d5..e81fcec 100644 --- a/storage/framework/views/7cc807de2c2a5b154e91d26d3ce81c15.php +++ b/storage/framework/views/7cc807de2c2a5b154e91d26d3ce81c15.php @@ -1,13 +1,15 @@
diff --git a/storage/framework/views/e70ba74b1d6919beb188eb00a9d97277.php b/storage/framework/views/e70ba74b1d6919beb188eb00a9d97277.php new file mode 100644 index 0000000..9e9915b --- /dev/null +++ b/storage/framework/views/e70ba74b1d6919beb188eb00a9d97277.php @@ -0,0 +1,259 @@ +startSection('title' , 'ویرایش پروفایل'); ?> + +startSection('account-content'); ?> +
+ + +
+
+
+ + +
+
+
+ + +
+ +
+ +
+ +
+
+stopSection(); ?> +startPush('scripts'); ?> + +stopPush(); ?> + +make('account.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?> \ No newline at end of file diff --git a/storage/framework/views/f639e2be3bb2c6ae8545a2e29df02f69.php b/storage/framework/views/f639e2be3bb2c6ae8545a2e29df02f69.php new file mode 100644 index 0000000..e687cda --- /dev/null +++ b/storage/framework/views/f639e2be3bb2c6ae8545a2e29df02f69.php @@ -0,0 +1,89 @@ +startSection('content'); ?> +
+ + + + + +
+stopSection(); ?> + +make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?> \ No newline at end of file diff --git a/storage/framework/views/fa69264b1e3575c27377188fc88729bb.php b/storage/framework/views/fa69264b1e3575c27377188fc88729bb.php index a04a7d9..7b66412 100644 --- a/storage/framework/views/fa69264b1e3575c27377188fc88729bb.php +++ b/storage/framework/views/fa69264b1e3575c27377188fc88729bb.php @@ -3,10 +3,10 @@ images && $flight->images->count() > 0): ?> images->count() > 1): ?> images; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $image): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> - <?php echo e($flight->flight_number); ?> + <?php echo e($flight->flight_number); ?> popLoop(); $loop = $__env->getLastLoop(); ?> - <?php echo e($flight->flight_number); ?> + <?php echo e($flight->flight_number); ?> <?php echo e($flight->flight_number); ?>