aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Http/Controllers/UserController.php
diff options
context:
space:
mode:
authorMarvin Borner2018-07-01 21:46:59 +0200
committerMarvin Borner2018-07-01 21:46:59 +0200
commitf7abf66d963770e60e2ed2a67fbeaa14e14568a6 (patch)
treec3b2a36f38e3e9d9e97ada0a723573da20720af7 /app/Http/Controllers/UserController.php
parent6c557a4be1a88de5dd681837bd77c50a98352168 (diff)
Added avatar preview and optimized avatar saving
Diffstat (limited to 'app/Http/Controllers/UserController.php')
-rw-r--r--app/Http/Controllers/UserController.php10
1 files changed, 7 insertions, 3 deletions
diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index 42f4e16..d82ee98 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -2,8 +2,11 @@
namespace App\Http\Controllers;
-use Illuminate\Http\Request;
use Auth;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Storage;
+use Illuminate\Foundation\Auth\User;
+use Intervention\Image\ImageManagerStatic as Image;
class UserController extends Controller
{
@@ -19,8 +22,9 @@ class UserController extends Controller
'avatar' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$user = Auth::user();
- $avatarName = $user->id . '_avatar' . time() . '.' . request()->avatar->getClientOriginalExtension();
- $request->avatar->storeAs('avatars', $avatarName);
+ $avatarName = $user->id . '.' . $request->avatar->getClientOriginalExtension();
+ $fittedAvatar = Image::make($request->avatar)->fit(256)->encode();
+ Storage::put('avatars/' . $avatarName, (string) $fittedAvatar);
$user->avatar = $avatarName;
$user->save();
return back()