OMNI Access
v1.3.0
Free
~8 min read
Blade Directives
Conditionally render Blade views with @role, @hasrole, @canrole, @permission, and related directives provided by OMNI Access.
01
Step 1 of 3
Role Directives
{{-- Check single role --}}
@role('admin')
<button>Admin Panel</button>
@endrole
{{-- Alternative syntax --}}
@hasrole('admin')
<p>Welcome Admin!</p>
@endhasrole
{{-- Check any role --}}
@hasanyrole('admin|editor')
<a href="/dashboard">Dashboard</a>
@endhasanyrole
{{-- Check all roles --}}
@hasallroles('admin|moderator')
<button>Super Controls</button>
@endhasallroles
{{-- Else condition --}}
@role('admin')
<p>Admin content</p>
@else
<p>Regular user content</p>
@endrole
{{-- Check single role --}}
@role('admin')
<button>Admin Panel</button>
@endrole
{{-- Alternative syntax --}}
@hasrole('admin')
<p>Welcome Admin!</p>
@endhasrole
{{-- Check any role --}}
@hasanyrole('admin|editor')
<a href="/dashboard">Dashboard</a>
@endhasanyrole
{{-- Check all roles --}}
@hasallroles('admin|moderator')
<button>Super Controls</button>
@endhasallroles
{{-- Else condition --}}
@role('admin')
<p>Admin content</p>
@else
<p>Regular user content</p>
@endrole
02
Step 2 of 3
Permission Directives
{{-- Check single permission --}}
@permission('posts.edit')
<button>Edit Post</button>
@endpermission
{{-- Alternative syntax --}}
@haspermission('posts.delete')
<button class="btn-danger">Delete</button>
@endhaspermission
{{-- Check any permission --}}
@hasanypermission('posts.edit|posts.create')
<div class="post-actions">
{{-- Show actions --}}
</div>
@endhasanypermission
{{-- Check all permissions --}}
@hasallpermissions('posts.edit|posts.publish')
<button>Edit & Publish</button>
@endhasallpermissions
{{-- Check single permission --}}
@permission('posts.edit')
<button>Edit Post</button>
@endpermission
{{-- Alternative syntax --}}
@haspermission('posts.delete')
<button class="btn-danger">Delete</button>
@endhaspermission
{{-- Check any permission --}}
@hasanypermission('posts.edit|posts.create')
<div class="post-actions">
{{-- Show actions --}}
</div>
@endhasanypermission
{{-- Check all permissions --}}
@hasallpermissions('posts.edit|posts.publish')
<button>Edit & Publish</button>
@endhasallpermissions
03
Step 3 of 3
Combined Examples
<nav>
@role('admin')
<a href="/admin">Admin Panel</a>
@endrole
@hasanyrole('editor|author')
<a href="/posts/create">New Post</a>
@endhasanyrole
@permission('users.view')
<a href="/users">Users</a>
@endpermission
</nav>
{{-- Post actions --}}
<div class="post-actions">
@permission('posts.edit')
<button class="btn btn-primary">Edit</button>
@endpermission
@permission('posts.delete')
<button class="btn btn-danger">Delete</button>
@else
<span class="text-muted">No delete permission</span>
@endpermission
</div>
<nav>
@role('admin')
<a href="/admin">Admin Panel</a>
@endrole
@hasanyrole('editor|author')
<a href="/posts/create">New Post</a>
@endhasanyrole
@permission('users.view')
<a href="/users">Users</a>
@endpermission
</nav>
{{-- Post actions --}}
<div class="post-actions">
@permission('posts.edit')
<button class="btn btn-primary">Edit</button>
@endpermission
@permission('posts.delete')
<button class="btn btn-danger">Delete</button>
@else
<span class="text-muted">No delete permission</span>
@endpermission
</div>
Community Discussions 0
Ask questions, share step solutions, or discuss software workflows with other professionals.
Moderated Community
Join the Community Discussion
Got stuck on a step or have a question about this configuration? Sign in to join the discussion and receive direct advice from instructors and peers.
Guide Checklist
3 Steps
Tutorial Progress
0%
No Discussions Yet
Have a question or found a clever tip for this guide? Start the conversation using the comment box above!