【发布时间】:2017-09-12 17:43:04
【问题描述】:
我正在使用 entrust 包进行角色管理,我已经根据 github 中提到的步骤在我的项目中实现了它,它工作正常,但是为了将角色分配给用户页面,我们从我下面提到的两个查询中获取值,如果用户列表达到 100,我如何轻松获取用户详细信息,我想要此视图的数据表,任何人都可以帮我查看数据表格式,并且我已经为我的项目配置了 yajra 数据表,它适用于其他页面,我们正在使用https://github.com/Zizaco/entrust
控制器.php
public function index()
{
$company_id=Auth::user()->company_id;
$users=User::where('company_id',$company_id)->get();
$allRoles=Role::where('company_id',$company_id)->get();
return view('usersroles.index',compact(['users','allRoles']));
}
view.blade.php
<table class="table table-bordered" >
<tr class="thead-cls">
<th class="center">Name</th>
<th class="center">Employee Id</th>
<th class="center">Roles</th>
<th class="center">Action</th>
</tr>
@forelse($users as $user)
<tr>
<td class="center">{{$user->name}}</td>
<td class="center">{{$user->emp_id}}</td>
<td class="center">
@foreach( $user->roles as $role)
{{$role->name}},
@endforeach
</td>
<td class="center">
@permission('users-roles-edit')
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-add" data-toggle="modal" data-target="#myModal-{{$user->id}}">
Edit
</button>
@endrole
<!-- Modal -->
<div class="modal fade" id="myModal-{{$user->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"> Editing<b> {{$user->name}}'s</b> Role</h4>
</div>
<div class="modal-body">
<form action="{{route('usersroles.update',$user->id)}}" method="post" role="form" id="role-form-{{$user->id}}">
{{csrf_field()}}
{{method_field('PATCH')}}
<div class="form-group">
<select name="roles[]" multiple required="">
@foreach($allRoles as $role)
<option value="{{$role->id}}">{{$role->name}}</option>
@endforeach
</select>
</div>
{{--<button type="submit" class="btn btn-primary">Submit</button>--}}
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-add" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary btn-add" onclick="$('#role-form-{{$user->id}}').submit()">Save changes</button>
</div>
</div>
</div>
</div>
</td>
</tr>
@empty
<td>No users</td>
@endforelse
</table>
[![Need Datatables for this view][1]][1]
【问题讨论】: