如何根据角色类别显示单独的许可?
我是Laravel Development的新手。我正在使用Spatie在Laravel的角色和权限工作,要显示一个权限列表的标题名称,例如我有财产权限列表,然后想在权限列表的顶部显示属性标题名称,而其他我有代理权限列表然后想在权限列表的顶部展示代理标题名称。
我有权限的表,其中添加了 cole_category_id 的列,该列与其他表 roun_categories
prole_categories的表
.net/1b3pv.png“ rel =“ nofollow noreferrer”>
位置
$permission = RoleCatgory::Leftjoin("permissions","role_categories.id","=","permissions.role_category_id")
->get();
我
@foreach($permission as $value)
<h3>{{ $value->category_name }}</h3>
@if(in_array($value['id'],$rolePermissions))
@php
$checked="checked";
@endphp
@else
@php
$checked="";
@endphp
@endif
<div class="col-md-4 mb-2">
<input type="checkbox" class="form-check-input" id="exampleCheck" name="permission[]" @php echo $checked; @endphp value="{{ $value->id }}">
label class="form-check-label" for="exampleCheck">{{ $value->name }}</label>
</div>
@endforeach
的控制器代码是我使用两个桌子的 在每个权限名称上,但只想在属性权限列表上显示一次
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的终端中运行此工匠命令
php手工制作:迁移craete_roles_ and_permissions_table
然后将以下代码添加到该迁移:
创建一个模型为
remo
App \ Models \ crom
类中的方法:创建模型为
许可
,然后将此方法添加到app \ models \允许
类:在您的控制器中,将$ coole变量传递到视图中:
最后,您可以在刀片中使用此关系:
如果您不熟悉这些概念,请阅读 laravel docs 。
run this artisan command in your terminal
php artisan make:migration craete_roles_and_permissions_table
then add the following code to that migration:
create a Model as
Role
and add this method inApp\Models\Role
class:create a Model as
Permission
and add this method inApp\Models\Permission
class:in your controller pass the $role variable into the view :
finally, you can use this Relation in your blade:
If you are not familiar with these concepts please read laravel docs.