diff options
Diffstat (limited to 'app/Http')
-rw-r--r-- | app/Http/Controllers/ImageController.php | 13 | ||||
-rw-r--r-- | app/Http/Controllers/UserController.php | 10 |
2 files changed, 8 insertions, 15 deletions
diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php index 37874f5..603008d 100644 --- a/app/Http/Controllers/ImageController.php +++ b/app/Http/Controllers/ImageController.php @@ -12,17 +12,6 @@ class ImageController extends Controller { $usersAvatar = User::findOrFail($user_id)->avatar; $storagePath = storage_path('app/public/avatars/' . $usersAvatar); - return Image::make($storagePath)->resize(100, 100)->response(); - - // $request->validate([ - // '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); - // $user->avatar = $avatarName; - // $user->save(); - // return back() - // ->with('success', 'You have successfully upload image.'); + return Image::make($storagePath)->response(); } } 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() |