Skip to content

Commit 3a86352

Browse files
committed
Fix VerifyRole and VerifyPermission to work with comma separated values
Due to middleware parameters https://laravel.com/docs/8.x/middleware#middleware-parameters
1 parent b180f18 commit 3a86352

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/App/Http/Middleware/VerifyPermission.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public function __construct(Guard $auth)
3535
*
3636
* @return mixed
3737
*/
38-
public function handle($request, Closure $next, $permission)
38+
public function handle($request, Closure $next, ...$permission)
3939
{
40-
if ($this->auth->check() && $this->auth->user()->hasPermission($permission)) {
40+
if ($this->auth->check() && $this->auth->user()->hasPermission(join(',', $permission))) {
4141
return $next($request);
4242
}
4343

src/App/Http/Middleware/VerifyRole.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ public function __construct(Guard $auth)
3535
*
3636
* @return mixed
3737
*/
38-
public function handle($request, Closure $next, $role)
38+
public function handle($request, Closure $next, ...$role)
3939
{
40-
$roles = explode('|', $role);
41-
for ($i = 0; $i < count($roles); $i++) {
42-
if ($this->auth->check() && $this->auth->user()->hasRole($roles[$i])) {
43-
return $next($request);
44-
}
40+
if ($this->auth->check() && $this->auth->user()->hasRole(join(',', $role))) {
41+
return $next($request);
4542
}
4643

4744
throw new RoleDeniedException($role);

0 commit comments

Comments
 (0)