aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/Http/Controllers/UserController.php29
-rw-r--r--config/filesystems.php2
-rw-r--r--database/migrations/2014_10_12_000000_create_users_table.php1
-rw-r--r--resources/views/layouts/app.blade.php52
-rw-r--r--resources/views/profile.blade.php51
-rw-r--r--routes/web.php11
6 files changed, 119 insertions, 27 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.');
+ }
+}
diff --git a/config/filesystems.php b/config/filesystems.php
index 77fa5de..af32c3c 100644
--- a/config/filesystems.php
+++ b/config/filesystems.php
@@ -13,7 +13,7 @@ return [
|
*/
- 'default' => env('FILESYSTEM_DRIVER', 'local'),
+ 'default' => env('FILESYSTEM_DRIVER', 'public'),
/*
|--------------------------------------------------------------------------
diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php
index 0b20550..53b1c70 100644
--- a/database/migrations/2014_10_12_000000_create_users_table.php
+++ b/database/migrations/2014_10_12_000000_create_users_table.php
@@ -17,6 +17,7 @@ class CreateUsersTable extends Migration
$table->string('name');
$table->string('email')->unique();
$table->string('password');
+ $table->string('avatar')->default('user.jpg');
$table->rememberToken();
$table->timestamps();
});
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php
index f6e81e3..d64fe27 100644
--- a/resources/views/layouts/app.blade.php
+++ b/resources/views/layouts/app.blade.php
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
+
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -20,6 +21,7 @@
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
+
<body>
<div id="app">
<nav class="navbar navbar-expand-md navbar-light navbar-laravel">
@@ -27,7 +29,8 @@
<a class="navbar-brand" href="{{ url('/') }}">
{{ config('app.name', 'Laravel') }}
</a>
- <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
+ <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
+ aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
<span class="navbar-toggler-icon"></span>
</button>
@@ -41,30 +44,34 @@
<ul class="navbar-nav ml-auto">
<!-- Authentication Links -->
@guest
- <li class="nav-item">
- <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
- </li>
+ <li class="nav-item">
+ <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
+ </li>
@else
- <li class="nav-item dropdown">
- <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
- {{ Auth::user()->name }} <span class="caret"></span>
- </a>
+ <li class="nav-item dropdown">
+ <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true"
+ aria-expanded="false" v-pre>
+ {{ Auth::user()->name }}
+ <span class="caret"></span>
+ </a>
- <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
- <a class="dropdown-item" href="{{ route('logout') }}"
- onclick="event.preventDefault();
+ <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
+ <a class="dropdown-item" href="/profile">
+ User Profile
+ </a>
+ <a class="dropdown-item" href="{{ route('logout') }}" onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
- {{ __('Logout') }}
- </a>
+ {{ __('Logout') }}
+ </a>
- <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
- @csrf
- </form>
- </div>
- </li>
+ <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
+ @csrf
+ </form>
+ </div>
+ </li>
@endguest
</ul>
</div>
@@ -76,4 +83,5 @@
</main>
</div>
</body>
-</html>
+
+</html> \ No newline at end of file
diff --git a/resources/views/profile.blade.php b/resources/views/profile.blade.php
new file mode 100644
index 0000000..e986cb7
--- /dev/null
+++ b/resources/views/profile.blade.php
@@ -0,0 +1,51 @@
+@extends('layouts.app') @section('content')
+<div class="container">
+ <div class="row">
+ @if ($message = Session::get('success'))
+
+ <div class="alert alert-success alert-block">
+
+ <button type="button" class="close" data-dismiss="alert">×</button>
+
+ <strong>{{ $message }}</strong>
+
+ </div>
+
+ @endif @if (count($errors) > 0)
+ <div class="alert alert-danger">
+ <strong>Whoops!</strong> There were some problems with your input.
+ <br>
+ <br>
+ <ul>
+ @foreach ($errors->all() as $error)
+ <li>{{ $error }}</li>
+ @endforeach
+ </ul>
+ </div>
+ @endif
+ </div>
+ <div class="row justify-content-center">
+
+ <div class="profile-header-container">
+ <div class="profile-header-img">
+ <img height="100px" width="100px" class="rounded-circle" src="/storage/avatars/{{ $user->avatar }}" />
+ <!-- badge -->
+ <div class="rank-label-container">
+ <span class="label label-default rank-label">{{$user->name}}</span>
+ </div>
+ </div>
+ </div>
+
+ </div>
+ <div class="row justify-content-center">
+ <form action="/avatar" method="post" enctype="multipart/form-data">
+ @csrf
+ <div class="form-group">
+ <input type="file" class="form-control-file" name="avatar" id="avatarFile" aria-describedby="fileHelp">
+ <small id="fileHelp" class="form-text text-muted">Please upload a valid image file. Size of image should not be more than 2MB.</small>
+ </div>
+ <button type="submit" class="btn btn-primary">Submit</button>
+ </form>
+ </div>
+</div>
+@endsection \ No newline at end of file
diff --git a/routes/web.php b/routes/web.php
index 7c0500f..11eaa5c 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -8,13 +8,16 @@
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
-*/
+ */
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
-Route::group(['middleware' => ['auth']], function() {
- Route::get('writeMessage', ['as'=>'writeMessage','uses'=>'SocketController@writeMessage']);
+Route::group(['middleware' => ['auth']], function () {
+ Route::get('profile', 'UserController@Profile');
+ Route::get('/', ['as' => 'writeMessage', 'uses' => 'SocketController@writeMessage']);
+
+ Route::post('avatar', 'UserController@updateAvatar');
Route::post('sendMessage', 'SocketController@sendMessage');
-}); \ No newline at end of file
+});