BladeOne
BladeOne copied to clipboard
@auth with multiple roles
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?