Skip to content

Blade directive @hasanyrole does not work with array of role names #2165

@boryn

Description

@boryn

Using blade templates this works:

@hasanyrole('admin|manager')
        It works
@endhasanyrole

Unfortunately this piece of code raises an error:

@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:

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions