From f77d871dff64a6940c34255c4fddcf162069f45b Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 21 Jan 2023 18:05:20 -0800 Subject: [PATCH] Use the imageHandler for profile avatar changes Signed-off-by: snipe --- app/Http/Controllers/ProfileController.php | 32 ++-------------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 739376e3ab..cf5f49feb0 100755 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -67,37 +67,9 @@ class ProfileController extends Controller $user->location_id = $request->input('location_id'); } + // Handle the avatar upload and/or delete if necessary + app('\App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'avatar', 'avatars', 'avatar'); - if ($request->input('avatar_delete') == 1) { - $user->avatar = null; - } - - - if ($request->hasFile('avatar')) { - $path = 'avatars'; - - if (! Storage::disk('public')->exists($path)) { - Storage::disk('public')->makeDirectory($path, 775); - } - - $upload = $image = $request->file('avatar'); - $ext = $image->getClientOriginalExtension(); - $file_name = 'avatar-'.str_random(18).'.'.$ext; - - if ($image->getClientOriginalExtension() != 'svg') { - $upload = Image::make($image->getRealPath())->resize(84, 84); - } - - // This requires a string instead of an object, so we use ($string) - Storage::disk('public')->put($path.'/'.$file_name, (string) $upload->encode()); - - // Remove Current image if exists - if (($user->avatar) && (Storage::disk('public')->exists($path.'/'.$user->avatar))) { - Storage::disk('public')->delete($path.'/'.$user->avatar); - } - - $user->avatar = $file_name; - } if ($user->save()) { return redirect()->route('profile')->with('success', 'Account successfully updated');