Skip to content
New issue

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

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

Already on GitHub? Sign in 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?

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

No branches or pull requests

1 participant