@@ 64-86 (lines=23) @@ | ||
61 | * @param bool $requireAll All roles in the array are required. |
|
62 | * @return bool |
|
63 | */ |
|
64 | public function hasRole($name, $requireAll = false) |
|
65 | { |
|
66 | if (is_array($name)) { |
|
67 | foreach ($name as $roleName) { |
|
68 | $hasRole = $this->hasRole($roleName); |
|
69 | ||
70 | if ($hasRole && !$requireAll) { |
|
71 | return true; |
|
72 | } elseif (!$hasRole && $requireAll) { |
|
73 | return false; |
|
74 | } |
|
75 | } |
|
76 | ||
77 | // If we've made it this far and $requireAll is FALSE, then NONE of the roles were found |
|
78 | // If we've made it this far and $requireAll is TRUE, then ALL of the roles were found. |
|
79 | // Return the value of $requireAll; |
|
80 | return $requireAll; |
|
81 | } else { |
|
82 | return $this->role->name == $name; |
|
83 | } |
|
84 | ||
85 | return false; |
|
86 | } |
|
87 | ||
88 | /** |
|
89 | * Check if user has a permission by its name. |
@@ 136-154 (lines=19) @@ | ||
133 | return $this->hasManyThrough($roleModel, $permissionModel);*/ |
|
134 | } |
|
135 | ||
136 | public function hasRole($name, $requireAll = false) |
|
137 | { |
|
138 | if (is_array($name)) { |
|
139 | foreach ($name as $roleName) { |
|
140 | $hasRole = $this->hasRole($roleName); |
|
141 | ||
142 | if ($hasRole && !$requireAll) { |
|
143 | return true; |
|
144 | } elseif (!$hasRole && $requireAll) { |
|
145 | return false; |
|
146 | } |
|
147 | } |
|
148 | return $requireAll; |
|
149 | } else { |
|
150 | return $this->role->name == $name; |
|
151 | } |
|
152 | ||
153 | return false; |
|
154 | } |
|
155 | ||
156 | public function can($permission, $requireAll = false) |
|
157 | { |