/
User.php
50 lines (39 loc) · 1000 Bytes
/
User.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace App;
use Storage;
use Cartalyst\Sentinel\Users\EloquentUser;
class User extends EloquentUser
{
protected $fillable = [
'email',
'password',
'last_name',
'first_name',
'permissions',
'avatar'
];
/**
* @return mixed
*/
public function getAvatarAttribute()
{
if (isset($this->attributes['avatar']) and $this->attributes['avatar']){
if (!is_file(public_path($this->attributes['avatar']))){
return '/img/not_avatar.jpg';
}
return $this->attributes['avatar'];
}
return '/img/not_avatar.jpg';
}
public function setAvatarAttribute($value)
{
if (empty($value) and $value == '/img/not_avatar.png'){
return false;
}
$path = files_move($value,'images/users/'.$this->id);;
if (!$path){
return false;
}
$this->attributes['avatar'] = $path;
}
}