Skip to content

A free open source IT asset/license management system

Use the imageHandler for profile avatar changes

snipef77d871dff64
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');