Skip to content

Commit 7567c5a

Browse files
committed
Upload & Restart Avatar, some improvements in styles, layouts, views, config avatar, use facades path
1 parent c2c9516 commit 7567c5a

32 files changed

+6369
-413
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ https://medium.com/modulr/create-scaffold-with-laravel-5-7-f5ab353dff1c
8383

8484
- Auth
8585
- Login
86-
- register
86+
- Register - generate avatar
8787
- Remember Password
8888

8989

9090
- Profile
91-
- Edit Name and email
91+
- Edit Name, email - regenerate avatar
9292
- Change password
93+
- Upload & Restart Avatar
9394

9495

9596
- Users & Roles --> _Comming soon..._
@@ -100,15 +101,17 @@ https://medium.com/modulr/create-scaffold-with-laravel-5-7-f5ab353dff1c
100101
##### Backend
101102
- [Laravel Authentication](https://laravel.com/docs/5.7/authentication)
102103
- [Laravolt Avatar](https://github.com/laravolt/avatar)
104+
- [Intervention Image](http://image.intervention.io/)
103105

104106

105107
##### Frontend
106108
- [Laravel Frontend](https://laravel.com/docs/5.7/frontend)
107109
- [Bootstrap 4](https://getbootstrap.com/)
108110
- [Core UI](https://coreui.io/)
109111
- [Fontawesome 5](https://fontawesome.com/)
110-
- [simple-line-icons](http://simplelineicons.com/)
111-
- [vue-toasted](https://shakee93.github.io/vue-toasted/)
112+
- [Simple Line Icons](http://simplelineicons.com/)
113+
- [Vue Toasted](https://shakee93.github.io/vue-toasted/)
114+
- [Vue Clip](https://vueclip.adonisjs.com/)
112115

113116

114117

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use Illuminate\Support\Facades\Hash;
88
use Illuminate\Support\Facades\Validator;
99
use Illuminate\Foundation\Auth\RegistersUsers;
10+
use Illuminate\Support\Facades\Storage;
1011

1112
use Avatar;
12-
use Storage;
1313

1414
class RegisterController extends Controller
1515
{

app/Http/Controllers/HomeController.php renamed to app/Http/Controllers/DashboardController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Illuminate\Http\Request;
66

7-
class HomeController extends Controller
7+
class DashboardController extends Controller
88
{
99
/**
1010
* Create a new controller instance.
@@ -23,6 +23,6 @@ public function __construct()
2323
*/
2424
public function index()
2525
{
26-
return view('home');
26+
return view('dashboard');
2727
}
2828
}

app/Http/Controllers/Profile/ProfileController.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
use Illuminate\Support\Facades\Auth;
99
use Illuminate\Support\Facades\Hash;
10+
use Illuminate\Support\Facades\Storage;
1011

12+
use App\Http\Helpers\Upload;
1113
use Avatar;
12-
use Storage;
1314

1415
use App\User;
1516

@@ -39,7 +40,7 @@ public function updateAuthUser (Request $request)
3940
return $user;
4041
}
4142

42-
public function updateAuthUserPassword(Request $request)
43+
public function updatePasswordAuthUser(Request $request)
4344
{
4445
$this->validate($request, [
4546
'current' => 'required',
@@ -58,4 +59,25 @@ public function updateAuthUserPassword(Request $request)
5859

5960
return $user;
6061
}
62+
63+
public function uploadAvatarAuthUser(Request $request)
64+
{
65+
$upload = new Upload();
66+
$avatar = $upload->upload($request->file, 'avatars/'.Auth::id())->resize(200, 200)->getData();
67+
68+
$user = User::find(Auth::id());
69+
$user->avatar = $avatar['basename'];
70+
$user->save();
71+
72+
return $user;
73+
}
74+
75+
public function removeAvatarAuthUser()
76+
{
77+
$user = User::find(Auth::id());
78+
$user->avatar = 'avatar.png';
79+
$user->save();
80+
81+
return $user;
82+
}
6183
}

app/Http/Helpers/Upload.php

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php namespace App\Http\Helpers;
2+
3+
use Illuminate\Support\Facades\Auth;
4+
use Illuminate\Support\Facades\Storage;
5+
use Image;
6+
7+
class Upload {
8+
9+
protected $file;
10+
protected $meta;
11+
protected $allowedResize = [
12+
'image/jpg',
13+
'image/jpeg',
14+
'image/png',
15+
'image/gif',
16+
];
17+
18+
/**
19+
* [upload description]
20+
* @param [file] $file [description]
21+
* @param [string] $path [description]
22+
* @return [obj] $this [description]
23+
*/
24+
public function upload($file, $path)
25+
{
26+
$this->file = $file;
27+
28+
$path = $this->file->store($path);
29+
30+
$this->getMeta($path);
31+
32+
return $this;
33+
}
34+
35+
/**
36+
* [uploadTemp description]
37+
* @param [file] $file [description]
38+
* @return [obj] $this [description]
39+
*/
40+
public function uploadTemp($file)
41+
{
42+
$this->file = $file;
43+
44+
$path = $this->file->store('temp/'.Auth::id());
45+
46+
$this->getMeta($path);
47+
48+
return $this;
49+
}
50+
/**
51+
* [move description]
52+
* @param [string] $from [path]
53+
* @param [string] $to [path]
54+
* @return [obj] $this [description]
55+
*/
56+
public function move($from, $to)
57+
{
58+
$this->getMeta($from);
59+
60+
$to = $to.'/'.$this->meta['basename'];
61+
62+
Storage::move($from, $to);
63+
64+
$this->getMeta($to);
65+
66+
return $this;
67+
}
68+
69+
/**
70+
* [resize description]
71+
* @param [integer] $width [pixels]
72+
* @param [integer] $height [pixels]
73+
* @return [obj] $this [description]
74+
*/
75+
public function resize($width=null, $height=null)
76+
{
77+
if (in_array($this->meta['type'], $this->allowedResize)) {
78+
79+
$file = Storage::get($this->meta['path']);
80+
81+
$img = Image::make($file)
82+
->fit($width, $height, function ($constraint) {
83+
//$constraint->aspectRatio();
84+
$constraint->upsize();
85+
})
86+
->encode();
87+
88+
$this->meta['size'] = strlen((string) $img);
89+
90+
Storage::put($this->meta['path'], (string) $img);
91+
}
92+
93+
return $this;
94+
}
95+
96+
/**
97+
* [thumbnail description]
98+
* @param [integer] $width [pixels]
99+
* @param [integer] $height [pixels]
100+
* @return [obj] $this [description]
101+
*/
102+
public function thumbnail($width=null, $height=null)
103+
{
104+
if (in_array($this->meta['type'], $this->allowedResize)) {
105+
106+
$file = Storage::get($this->meta['path']);
107+
108+
$img = Image::make($file)
109+
->fit($width, $height)
110+
// ->resize($width, $height, function ($constraint) {
111+
// $constraint->aspectRatio();
112+
// $constraint->upsize();
113+
// })
114+
// ->crop($width, $height)
115+
->encode();
116+
117+
Storage::put($this->meta['dirname'].'/thumbnail_'.$this->meta['basename'], (string) $img);
118+
}
119+
120+
return $this;
121+
}
122+
123+
/**
124+
* [getData description]
125+
* @return [array] [description]
126+
*/
127+
public function getData()
128+
{
129+
return $this->meta;
130+
}
131+
132+
/**
133+
* [getMeta description]
134+
* @param [string] $path [description]
135+
* @return [obj] $this [description]
136+
*/
137+
private function getMeta($path)
138+
{
139+
$this->meta = pathinfo($path);
140+
$this->meta['path'] = $path;
141+
142+
if ($this->file) {
143+
$this->meta['name'] = $this->file->getClientOriginalName();
144+
$this->meta['type'] = $this->file->getClientMimeType();
145+
$this->meta['size'] = $this->file->getClientSize();
146+
$this->meta['isValid'] = $this->file->isValid();
147+
$this->meta['maxFileSize'] = $this->file->getMaxFilesize();
148+
$this->meta['error'] = $this->file->getError();
149+
$this->meta['errorMessage'] = $this->file->getErrorMessage();
150+
} else {
151+
$this->meta['type'] = Storage::mimeType($path);
152+
$this->meta['size'] = Storage::size($path);
153+
$this->meta['meta'] = Storage::getMetaData($path);
154+
}
155+
156+
return $this;
157+
}
158+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"require": {
88
"php": "^7.1.3",
99
"fideloper/proxy": "^4.0",
10+
"intervention/image": "^2.4",
1011
"laravel/framework": "5.7.*",
1112
"laravel/tinker": "^1.0",
1213
"laravolt/avatar": "^2.0"

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/image.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Image Driver
8+
|--------------------------------------------------------------------------
9+
|
10+
| Intervention Image supports "GD Library" and "Imagick" to process images
11+
| internally. You may choose one of them according to your PHP
12+
| configuration. By default PHP's "GD Library" implementation is used.
13+
|
14+
| Supported: "gd", "imagick"
15+
|
16+
*/
17+
18+
'driver' => 'gd'
19+
20+
];

config/laravolt/avatar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
'ascii' => false,
2626

2727
// Image shape: circle or square
28-
'shape' => 'circle',
28+
'shape' => 'square',
2929

3030
// Image width, in pixel
3131
'width' => 200,
@@ -71,7 +71,7 @@
7171
],
7272

7373
'border' => [
74-
'size' => 1,
74+
'size' => 0,
7575

7676
// border color, available value are:
7777
// 'foreground' (same as foreground color)

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@fortawesome/fontawesome-free": "^5.3.1",
2727
"perfect-scrollbar": "^1.4.0",
2828
"simple-line-icons": "^2.4.1",
29+
"vue-clip": "^1.0.0",
2930
"vue-toasted": "^1.1.24"
3031
}
3132
}

0 commit comments

Comments
 (0)