-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathUserMethod.php
103 lines (90 loc) · 1.89 KB
/
UserMethod.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace App\Domains\Auth\Models\Traits\Method;
use Illuminate\Support\Collection;
/**
* Trait UserMethod.
*/
trait UserMethod
{
/**
* @return bool
*/
public function isMasterAdmin(): bool
{
return $this->id === 1;
}
/**
* @return mixed
*/
public function isAdmin(): bool
{
return $this->type === self::TYPE_ADMIN;
}
/**
* @return mixed
*/
public function isUser(): bool
{
return $this->type === self::TYPE_USER;
}
/**
* @return mixed
*/
public function hasAllAccess(): bool
{
return $this->isAdmin() && $this->hasRole(config('boilerplate.access.role.admin'));
}
/**
* @param $type
* @return bool
*/
public function isType($type): bool
{
return $this->type === $type;
}
/**
* @return mixed
*/
public function canChangeEmail(): bool
{
return config('boilerplate.access.user.change_email');
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->active;
}
/**
* @return bool
*/
public function isVerified(): bool
{
return $this->email_verified_at !== null;
}
/**
* @return bool
*/
public function isSocial(): bool
{
return $this->provider && $this->provider_id;
}
/**
* @return Collection
*/
public function getPermissionDescriptions(): Collection
{
return $this->permissions->pluck('description');
}
/**
* @param bool $size
* @return mixed|string
*
* @throws \Creativeorange\Gravatar\Exceptions\InvalidEmailException
*/
public function getAvatar($size = null)
{
return 'https://gravatar.com/avatar/'.md5(strtolower(trim($this->email))).'?s='.config('boilerplate.avatar.size', $size).'&d=mp';
}
}