1 | <?php |
||
11 | trait Administrable |
||
12 | { |
||
13 | /** |
||
14 | * New filled roles. |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | private $_roles; |
||
19 | |||
20 | /** |
||
21 | * @var int|null |
||
22 | */ |
||
23 | private $_countAdministrativeRoles; |
||
24 | |||
25 | /** |
||
26 | * User identifier. |
||
27 | * |
||
28 | * @return int |
||
29 | */ |
||
30 | public function getIdAttribute(): int |
||
34 | |||
35 | /** |
||
36 | * User name. |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | public function getNameAttribute(): string |
||
44 | |||
45 | /** |
||
46 | * Set new filled roles. |
||
47 | * |
||
48 | * @param $value |
||
49 | * @return void |
||
50 | */ |
||
51 | public function setRolesAttribute($value): void |
||
55 | |||
56 | /** |
||
57 | * Get user roles by relation. |
||
58 | * |
||
59 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
60 | */ |
||
61 | public function roles() |
||
65 | |||
66 | /** |
||
67 | * Checks if User has access to $permissions. |
||
68 | * |
||
69 | * @param array $permissions |
||
70 | * @return bool |
||
71 | */ |
||
72 | public function hasAccess(array $permissions) : bool |
||
83 | |||
84 | /** |
||
85 | * Checks if the user belongs to role. |
||
86 | * |
||
87 | * @param string $roleSlug |
||
88 | * @return bool |
||
89 | */ |
||
90 | public function inRole(string $roleSlug): bool |
||
94 | |||
95 | /** |
||
96 | * @param RbacUserContract $member |
||
97 | * @param Role $role |
||
98 | * @return bool |
||
99 | */ |
||
100 | public function canAssignRole(RbacUserContract $member, Role $role): bool |
||
119 | |||
120 | /** |
||
121 | * Synchronize user roles after save model. |
||
122 | * |
||
123 | * @param array $options |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function save(array $options = []) |
||
138 | |||
139 | /** |
||
140 | * @return int |
||
141 | */ |
||
142 | private function countAdministrativeRoles(): int |
||
159 | } |
||
160 |
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: