aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Http
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
parent6c557a4be1a88de5dd681837bd77c50a98352168 (diff)
Added avatar preview and optimized avatar saving
Diffstat (limited to 'app/Http')
-rw-r--r--app/Http/Controllers/ImageController.php13
-rw-r--r--app/Http/Controllers/UserController.php10
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()