Repository: spatie/laravel-permission (php)

Issue:
@role is not accepting an array
He, I'm check on multiple gaurds but is not working. If I just pass through 'admin' it works.

```php
@role('superadmin', 'admin')
# you may edit this stuff
@else # this is error some times
# you may not edit this stuff
@endrole

```
In the readme [here](https://github.com/spatie/laravel-permission#using-blade-directives-with-multiple-guards) it says that it should work. But it does not.
Blade directive `@hasanyrole` does not work with array of role names
Using blade templates this works:
```blade
@hasanyrole('admin|manager')
        It works
@endhasanyrole
```

Unfortunately this piece of code raises an error:
```blade
@hasanyrole(['admin', 'manager'])
        This should work, too
@endhasanyrole
```

The error points to the line with `@hasanyrole` and says: `ParseError syntax error, unexpected ']', expecting ')'`

According to documentation at https://spatie.be/docs/laravel-permission/v5/basic-usage/blade-directives we should be able to pass `$collectionOfRoles`

PS. This works as well:
```blade
@if(auth()->user()->hasAnyRole(['admin', 'manager']))
        This works as well
@endif
```

**Versions**
- spatie/laravel-permission package version: 5.5.5
- laravel: 8.79.0
- PHP version: 7.4.19
- Database version: 10.6.4-MariaDB-log

**Expected behavior**
`@hasanyrole` should accept arrays



Pull request:
Support static arrays on blade directives
Closes #2165
Closes https://github.com/spatie/laravel-permission/issues/1997#issuecomment-1019023930
Closes https://github.com/spatie/laravel-permission/issues/626#issuecomment-358911209
Closes #309

This PR adds support for arrays(also expressions) on blade directives, example

```blade
@hasanyrole(['admin', 'manager'])
        
@endhasanyrole

@hasallroles(['admin', 'manager'])
        
@endhasallroles
```

Without this PR only `PIPE` an `VARIABLE's REF` are supported
https://github.com/spatie/laravel-permission/blob/dbc6c18ef4b2d097350a5faf82382564748e6c97/tests/resources/views/guardHasAllRolesPipe.blade.php#L1-L1
https://github.com/spatie/laravel-permission/blob/dbc6c18ef4b2d097350a5faf82382564748e6c97/tests/resources/views/guardHasAllRoles.blade.php#L1-L1


Patch:
diff --git a/src/PermissionServiceProvider.php b/src/PermissionServiceProvider.php
index 61fc132..e408064 100644
--- a/src/PermissionServiceProvider.php
+++ b/src/PermissionServiceProvider.php
@@ -84,62 +84,53 @@ class PermissionServiceProvider extends ServiceProvider
         $this->app->bind(RoleContract::class, $config['role']);
     }
 
+    public static function bladeMethodWrapper($method, $role, $guard = null)
+    {
+        return auth($guard)->check() && auth($guard)->user()->{$method}($role);
+    }
+
     protected function registerBladeExtensions($bladeCompiler)
     {
         $bladeCompiler->directive('role', function ($arguments) {
-            list($role, $guard) = explode(',', $arguments.',');
-
-            return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>";
+            return "<?php if(\\Spatie\\Permission\\PermissionServiceProvider::bladeMethodWrapper('hasRole', {$arguments})): ?>";
         });
         $bladeCompiler->directive('elserole', function ($arguments) {
-            list($role, $guard) = explode(',', $arguments.',');
-
-            return "<?php elseif(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>";
+            return "<?php elseif(\\Spatie\\Permission\\PermissionServiceProvider::bladeMethodWrapper('hasRole', {$arguments})): ?>";
         });
         $bladeCompiler->directive('endrole', function () {
             return '<?php endif; ?>';
         });
 
         $bladeCompiler->directive('hasrole', function ($arguments) {
-            list($role, $guard) = explode(',', $arguments.',');
-
-            return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>";
+            return "<?php if(\\Spatie\\Permission\\PermissionServiceProvider::bladeMethodWrapper('hasRole', {$arguments})): ?>";
         });
         $bladeCompiler->directive('endhasrole', function () {
             return '<?php endif; ?>';
         });
 
         $bladeCompiler->directive('hasanyrole', function ($arguments) {
-            list($roles, $guard) = explode(',', $arguments.',');
-
-            return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasAnyRole({$roles})): ?>";
+            return "<?php if(\\Spatie\\Permission\\PermissionServiceProvider::bladeMethodWrapper('hasAnyRole', {$arguments})): ?>";
         });
         $bladeCompiler->directive('endhasanyrole', function () {
             return '<?php endif; ?>';
         });
 
         $bladeCompiler->directive('hasallroles', function ($arguments) {
-            list($roles, $guard) = explode(',', $arguments.',');
-
-            return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasAllRoles({$roles})): ?>";
+            return "<?php if(\\Spatie\\Permission\\PermissionServiceProvider::bladeMethodWrapper('hasAllRoles', {$arguments})): ?>";
         });
         $bladeCompiler->directive('endhasallroles', function () {
             return '<?php endif; ?>';
         });
 
         $bladeCompiler->directive('unlessrole', function ($arguments) {
-            list($role, $guard) = explode(',', $arguments.',');
-
-            return "<?php if(!auth({$guard})->check() || ! auth({$guard})->user()->hasRole({$role})): ?>";
+            return "<?php if(! \\Spatie\\Permission\\PermissionServiceProvider::bladeMethodWrapper('hasRole', {$arguments})): ?>";
         });
         $bladeCompiler->directive('endunlessrole', function () {
             return '<?php endif; ?>';
         });
 
         $bladeCompiler->directive('hasexactroles', function ($arguments) {
-            list($roles, $guard) = explode(',', $arguments.',');
-
-            return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasExactRoles({$roles})): ?>";
+            return "<?php if(\\Spatie\\Permission\\PermissionServiceProvider::bladeMethodWrapper('hasExactRoles', {$arguments})): ?>";
         });
         $bladeCompiler->directive('endhasexactroles', function () {
             return '<?php endif; ?>';


Test patch:
diff --git a/tests/BladeTest.php b/tests/BladeTest.php
index 8558f50..21d6643 100644
--- a/tests/BladeTest.php
+++ b/tests/BladeTest.php
@@ -31,9 +31,9 @@ class BladeTest extends TestCase
         $this->assertEquals('does not have permission', $this->renderView('can', ['permission' => $permission]));
         $this->assertEquals('does not have role', $this->renderView('role', compact('role', 'elserole')));
         $this->assertEquals('does not have role', $this->renderView('hasRole', compact('role', 'elserole')));
-        $this->assertEquals('does not have all of the given roles', $this->renderView('hasAllRoles', $roles));
+        $this->assertEquals('does not have all of the given roles', $this->renderView('hasAllRoles', compact('roles')));
         $this->assertEquals('does not have all of the given roles', $this->renderView('hasAllRoles', ['roles' => implode('|', $roles)]));
-        $this->assertEquals('does not have any of the given roles', $this->renderView('hasAnyRole', $roles));
+        $this->assertEquals('does not have any of the given roles', $this->renderView('hasAnyRole', compact('roles')));
         $this->assertEquals('does not have any of the given roles', $this->renderView('hasAnyRole', ['roles' => implode('|', $roles)]));
     }
 
@@ -262,6 +262,33 @@ class BladeTest extends TestCase
         $this->assertEquals('does not have all of the given roles', $this->renderView('guardHasAllRolesPipe', compact('guard')));
     }
 
+    /** @test */
+    public function the_hasallroles_directive_will_evaluate_true_when_the_logged_in_user_does_have_all_required_roles_in_array()
+    {
+        $guard = 'admin';
+
+        $admin = $this->getSuperAdmin();
+
+        $admin->assignRole('moderator');
+
+        auth('admin')->setUser($admin);
+
+        $this->assertEquals('does have all of the given roles', $this->renderView('guardHasAllRolesArray', compact('guard')));
+    }
+
+    /** @test */
+    public function the_hasallroles_directive_will_evaluate_false_when_the_logged_in_user_doesnt_have_all_required_roles_in_array()
+    {
+        $guard = '';
+        $user = $this->getMember();
+
+        $user->assignRole('writer');
+
+        auth()->setUser($user);
+
+        $this->assertEquals('does not have all of the given roles', $this->renderView('guardHasAllRolesArray', compact('guard')));
+    }
+
     protected function getWriter()
     {
         $this->testUser->assignRole('writer');
diff --git a/tests/resources/views/guardHasAllRolesArray.blade.php b/tests/resources/views/guardHasAllRolesArray.blade.php
new file mode 100644
index 0000000..6ba51c1
--- /dev/null
+++ b/tests/resources/views/guardHasAllRolesArray.blade.php
@@ -0,0 +1,5 @@
+@hasallroles(['super-admin', 'moderator'], $guard)
+does have all of the given roles
+@else
+does not have all of the given roles
+@endhasallroles