diff options
author | Marvin Borner | 2018-07-01 12:13:36 +0200 |
---|---|---|
committer | Marvin Borner | 2018-07-01 12:13:36 +0200 |
commit | e7307d3241fb1f31a10ef92565c17b224d5983f0 (patch) | |
tree | 94f9f60fdd03f214306dcbf81ea57a0bade2df60 /app/Http | |
parent | f5500ae2c3c789a99674cd3e5b62054f1768423d (diff) |
Added user avatars
Diffstat (limited to 'app/Http')
-rw-r--r-- | app/Http/Controllers/UserController.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php new file mode 100644 index 0000000..1e2b204 --- /dev/null +++ b/app/Http/Controllers/UserController.php @@ -0,0 +1,29 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; +use Auth; + +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 . '_avatar' . time() . '.' . request()->avatar->getClientOriginalExtension(); + $request->avatar->storeAs('avatars', $avatarName); + $user->avatar = $avatarName; + $user->save(); + return back() + ->with('success', 'You have successfully upload image.'); + } +} |