BladeOne icon indicating copy to clipboard operation
BladeOne copied to clipboard

@auth with multiple roles

Open eljakim opened this issue 1 year ago • 0 comments

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?

eljakim avatar Nov 01 '23 11:11 eljakim