【问题标题】:Laravel Datatables while using Entrust Package使用 Entrust 包时的 Laravel 数据表
【发布时间】: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">&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]

【问题讨论】:

    标签: php laravel package


    【解决方案1】:

    只需使用jQuery 在您的视图中添加这段代码:

    $(document).ready(function(){
        $('#myTable').DataTable();
    });
    

    #myTable 是您的表的 ID。欲了解更多信息,read the documentation

    【讨论】:

    • 可以在不使用数据表的情况下添加它
    • 是的。但你指的是dataTables。你的具体问题是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 2016-07-28
    • 1970-01-01
    • 2016-12-04
    • 2016-10-19
    • 1970-01-01
    • 2016-04-13
    相关资源
    最近更新 更多