使用Entrust Package时的Laravel数据表

时间:2017-09-12 07:22:26

标签: php laravel package

我使用委托包进行角色管理,我已经在我的项目中根据github中提到的步骤实现了它,它工作正常但是为了将角色分配给用户页面,我们从我在下面提到的两个查询,如果用户列表达到100,我怎么能轻松获得用户详细信息,我想要这个视图的数据表可以任何人请帮助我查看数据表格式,我已经为我的项目配置了yajra数据表,它是在其他网页上工作时,我们正在使用https://github.com/Zizaco/entrust

Controller.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">&times;</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]

1 个答案:

答案 0 :(得分:0)

只需使用jQuery

在视图中添加此段代码即可
$(document).ready(function(){
    $('#myTable').DataTable();
});

#myTable是您表格的ID。有关详细信息,请read the documentation