diff options
-rw-r--r-- | app/Http/Controllers/ImageController.php | 28 | ||||
-rw-r--r-- | app/Http/Controllers/UserController.php | 2 | ||||
-rwxr-xr-x | composer.json | 1 | ||||
-rwxr-xr-x | composer.lock | 187 | ||||
-rw-r--r-- | resources/views/profile.blade.php | 2 | ||||
-rw-r--r-- | routes/web.php | 1 |
6 files changed, 218 insertions, 3 deletions
diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php new file mode 100644 index 0000000..37874f5 --- /dev/null +++ b/app/Http/Controllers/ImageController.php @@ -0,0 +1,28 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; +use Illuminate\Foundation\Auth\User; +use Intervention\Image\ImageManagerStatic as Image; + +class ImageController extends Controller +{ + public function getAvatar($user_id) + { + $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.'); + } +} diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 1e2b204..42f4e16 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -24,6 +24,6 @@ class UserController extends Controller $user->avatar = $avatarName; $user->save(); return back() - ->with('success', 'You have successfully upload image.'); + ->with('success', 'You have successfully uploaded the avatar.'); } } diff --git a/composer.json b/composer.json index c300898..a445b9f 100755 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^7.1.3", "fideloper/proxy": "^4.0", + "intervention/image": "^2.4", "laravel/framework": "5.6.*", "laravel/tinker": "^1.0", "predis/predis": "^1.1" diff --git a/composer.lock b/composer.lock index a5b07f6..d97cd3e 100755 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "39624abab302b95b7bb189af09fc60f3", + "content-hash": "da039ad8b363534701aac343cf6e633f", "packages": [ { "name": "dnoegel/php-xdg-base-dir", @@ -367,6 +367,141 @@ "time": "2018-02-07T20:20:57+00:00" }, { + "name": "guzzlehttp/psr7", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2017-03-20T17:10:46+00:00" + }, + { + "name": "intervention/image", + "version": "2.4.2", + "source": { + "type": "git", + "url": "https://github.com/Intervention/image.git", + "reference": "e82d274f786e3d4b866a59b173f42e716f0783eb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/image/zipball/e82d274f786e3d4b866a59b173f42e716f0783eb", + "reference": "e82d274f786e3d4b866a59b173f42e716f0783eb", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "guzzlehttp/psr7": "~1.1", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "~0.9.2", + "phpunit/phpunit": "^4.8 || ^5.7" + }, + "suggest": { + "ext-gd": "to use GD library based image processing.", + "ext-imagick": "to use Imagick based image processing.", + "intervention/imagecache": "Caching extension for the Intervention Image library" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + }, + "laravel": { + "providers": [ + "Intervention\\Image\\ImageServiceProvider" + ], + "aliases": { + "Image": "Intervention\\Image\\Facades\\Image" + } + } + }, + "autoload": { + "psr-4": { + "Intervention\\Image\\": "src/Intervention/Image" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@olivervogel.com", + "homepage": "http://olivervogel.com/" + } + ], + "description": "Image handling and manipulation library with support for Laravel integration", + "homepage": "http://image.intervention.io/", + "keywords": [ + "gd", + "image", + "imagick", + "laravel", + "thumbnail", + "watermark" + ], + "time": "2018-05-29T14:19:03+00:00" + }, + { "name": "jakub-onderka/php-console-color", "version": "0.1", "source": { @@ -1070,6 +1205,56 @@ "time": "2017-02-14T16:28:37+00:00" }, { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, + { "name": "psr/log", "version": "1.0.2", "source": { diff --git a/resources/views/profile.blade.php b/resources/views/profile.blade.php index e986cb7..adbae95 100644 --- a/resources/views/profile.blade.php +++ b/resources/views/profile.blade.php @@ -28,7 +28,7 @@ <div class="profile-header-container"> <div class="profile-header-img"> - <img height="100px" width="100px" class="rounded-circle" src="/storage/avatars/{{ $user->avatar }}" /> + <img height="100px" width="100px" class="rounded-circle" src="/avatar/{{ $user->id }}" /> <!-- badge --> <div class="rank-label-container"> <span class="label label-default rank-label">{{$user->name}}</span> diff --git a/routes/web.php b/routes/web.php index 11eaa5c..7c1f90e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -16,6 +16,7 @@ Route::get('/', function () { Auth::routes(); Route::group(['middleware' => ['auth']], function () { Route::get('profile', 'UserController@Profile'); + Route::get('avatar/{user_id}', 'ImageController@getAvatar'); Route::get('/', ['as' => 'writeMessage', 'uses' => 'SocketController@writeMessage']); Route::post('avatar', 'UserController@updateAvatar'); |