mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Use the imageHandler for profile avatar changes
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
3674f46ce0
commit
f77d871dff
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue