1
|
|
|
<?php namespace Arcanesoft\Auth\Models\Presenters; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class UserPresenter |
5
|
|
|
* |
6
|
|
|
* @package Arcanesoft\Auth\Models\Observers |
7
|
|
|
* @author ARCANEDEV <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @property string full_name |
10
|
|
|
* @property string since_date |
11
|
|
|
* @property string gravatar |
12
|
|
|
* @property string formatted_last_activity |
13
|
|
|
* |
14
|
|
|
* @property \Carbon\Carbon last_activity |
15
|
|
|
* @property \Carbon\Carbon created_at |
16
|
|
|
*/ |
17
|
|
|
trait UserPresenter |
18
|
|
|
{ |
19
|
|
|
/* ------------------------------------------------------------------------------------------------ |
20
|
|
|
| Traits |
21
|
|
|
| ------------------------------------------------------------------------------------------------ |
22
|
|
|
*/ |
23
|
|
|
use HasherTrait; |
24
|
|
|
|
25
|
|
|
/* ------------------------------------------------------------------------------------------------ |
26
|
|
|
| Getters & Setters |
27
|
|
|
| ------------------------------------------------------------------------------------------------ |
28
|
|
|
*/ |
29
|
|
|
/** |
30
|
|
|
* Get the `full_name` attribute or use the username if empty. |
31
|
|
|
* |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
public function getFullNameAttribute() |
35
|
|
|
{ |
36
|
|
|
$fullName = trim("{$this->first_name} {$this->last_name}"); |
|
|
|
|
37
|
|
|
|
38
|
|
|
return empty($fullName) ? $this->username : $fullName; |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get the `since_date` attribute (translated). |
43
|
|
|
* |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
public function getSinceDateAttribute() |
47
|
|
|
{ |
48
|
|
|
return trans('auth::users.since', [ |
49
|
|
|
'date' => $this->created_at->toFormattedDateString() |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get the `gravatar` attribute. |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function getGravatarAttribute() |
59
|
|
|
{ |
60
|
|
|
return gravatar() |
61
|
|
|
->setDefaultImage('mm')->setSize(160) |
62
|
|
|
->src($this->email); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the `formatted_last_activity` attribute. |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getFormattedLastActivityAttribute() |
71
|
|
|
{ |
72
|
|
|
return is_null($this->last_activity) |
73
|
|
|
? trans('auth::users.no-activity') |
74
|
|
|
: $this->last_activity->diffForHumans(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: