|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models\Concerns\User; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Hash; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @property string|null $telegram_chat_id |
|
9
|
|
|
* @property string $username |
|
10
|
|
|
* @property string $fullname |
|
11
|
|
|
* @property string $email |
|
12
|
|
|
* @property string $phone_country |
|
13
|
|
|
* @property \Propaganistas\LaravelPhone\PhoneNumber $phone |
|
14
|
|
|
* @property \Illuminate\Support\Carbon $email_verified_at |
|
15
|
|
|
* @property string $password |
|
16
|
|
|
* @property string $remember_token |
|
17
|
|
|
* @property boolean $is_active |
|
18
|
|
|
* @property string $is_active_badge |
|
19
|
|
|
* @property-read string $role |
|
20
|
|
|
* @property string $gravatar_image |
|
21
|
|
|
* |
|
22
|
|
|
* @see \App\Models\User |
|
23
|
|
|
*/ |
|
24
|
|
|
trait Attribute |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Set "password" attribute value. |
|
28
|
|
|
* |
|
29
|
|
|
* @param mixed $value |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
73 |
|
public function setPasswordAttribute($value) |
|
33
|
|
|
{ |
|
34
|
73 |
|
$this->attributes['password'] = Hash::make($value); |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
73 |
|
return $this; |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Return "is_active_badge" attribute value. |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
1 |
|
public function getIsActiveBadgeAttribute(): string |
|
45
|
|
|
{ |
|
46
|
1 |
|
if ($this->is_active) { |
|
47
|
1 |
|
return sprintf(<<<'html' |
|
48
|
1 |
|
<div class="badge badge-success">%s</div> |
|
49
|
1 |
|
html, trans('Active')); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return sprintf(<<<'html' |
|
53
|
|
|
<div class="badge badge-danger">%s</div> |
|
54
|
|
|
html, trans('Not Active')); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Return "role" attribute value. |
|
59
|
|
|
* |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
1 |
|
public function getRoleAttribute(): string |
|
63
|
|
|
{ |
|
64
|
1 |
|
$this->load('roles:id,name'); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
1 |
|
return $this->roles->first()->name; |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Return "gravatar_image" attribute value. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
19 |
|
public function getGravatarImageAttribute(): string |
|
75
|
|
|
{ |
|
76
|
19 |
|
return gravatar_image($this->email); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|