Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

@auth with multiple roles #181

Open
eljakim opened this issue Nov 1, 2023 · 0 comments
Open

@auth with multiple roles #181

eljakim opened this issue Nov 1, 2023 · 0 comments

Comments

@eljakim
Copy link

eljakim commented Nov 1, 2023

Because we tend to have projects where multiple roles may have access to specific features, we find ourselves creating a derive BladeOne class, with only the following overriding method:

    protected function compileAuth($expression = ''): string
    {
        $expression = $this->stripParentheses($expression);
        if ($expression) {
            $roles = '"' . implode('","', explode(',', $expression)) . '"';
            return $this->phpTag . "if(isset(\$this->currentUser) && in_array(\$this->currentRole, [$roles])): ?>";
        }
        return $this->phpTag . 'if(isset($this->currentUser)): ?>';
    }

This way we can do this:

     @auth(superadmin,admin)
                <a class="btn btn-outline-primary btn-sm" href="@asset('x/y/edit')">Edit</a>
     @endauth

Would it be possible to allow this in bladeOne out of the box?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant