Laravel Entrust角色&权限

时间:2017-03-17 09:04:10

标签: php laravel entrust

您好我希望能够从我的管理面板为角色分配权限我获得了权限foreach角色,但我可以保存它们看到 Photo我现在想要检查框并将选中的框与数据库同步,以便为角色保存权限 这是我的观点:

 {!! Form::open(['route' => 'permission.save']) !!}

    <div class="content table-responsive table-full-width">
        <table class="table">
            <thead>
                <tr>
                    <th>Name</th>
                    @foreach($roles as $role)
                        <th>{{ $role->display_name }}</th>
                    @endforeach
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody id="tables">
                @if(count($permissions))
                    @foreach($permissions as $permission)
                        <tr>
                            <td>{{ $permission->display_name ?: $permission->name }}</td>
                            @foreach($roles as $role)
                                <td>
                                    {!! Form::checkbox("roles[{$role->id}][]", $permission->id, $role->hasPermission($permission->name)) !!}
                                </td>
                            @endforeach
                            <td class="td-actions ">
                            <a style="height: 40px; width: 40px;" class=" remove btn btn-icon btn-danger">
                                <i style="margin-top: 3px;" class="fa fa-remove"></i>
                            </a>

                        </td>
                        </tr>
                    @endforeach
                @endif
            </tbody>
        </table>

        <button type="submit" class="btn btn-primary">Save</button>
    </div>
    {!! Form::close() !!}

这是我的控制器

    public function saveRolePermissions(Request $request)
{
    $roles = $request->get('roles');
    $allRoles = $this->roles->pluck('id');
    // dd($allRoles);
    foreach ($allRoles as $role) {

        $permissions = array_get($roles, $role, []);
        // if (!$role->perms()->get()->contains('id', $permission->id)) {
            $role->attachPermission($permission);
        // }

    }
}

0 个答案:

没有答案