blob: 2cfbea7774f27ba5fcc4dbe9c5a1ab996a52c7c2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<?php
namespace App\Http\Controllers;
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
{
public function Profile()
{
$user = Auth::user();
return view('profile', compact('user', $user));
}
public function updateAvatar(Request $request)
{
$request->validate([
'avatar' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$user = Auth::user();
$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 response()->json(array('success'=>'You have successfully uploaded the avatar.'));
}
}
|