public function createPermission($name, $display_name, $description, $isDisplay = 1, $power = '') { // 先检查存在不存在 $permission = Permission::where('name', '=', $name)->get()->first(); if ($permission) { return $permission->id; } //创建权限 $manageMenu = new Permission(); $manageMenu->name = $name; $manageMenu->display_name = $display_name; $manageMenu->description = $description; $manageMenu->isDisplay = $isDisplay; $manageMenu->power = $power; $manageMenu->save(); return $manageMenu->id; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $show['role'] = Role::where('id', '=', $id)->first(); $show['permissions'] = Permission::all(); // 获取全部权限, 用来判断那些全选选中了 $permissions = DB::table('permission_role')->where('role_id', '=', $id)->get(); foreach ($permissions as $value) { $show['selected_permissions'][$value->permission_id] = 1; } return View('admin.role.edit', ['title' => '后台管理 - 修改角色', 'show' => $show]); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $show['role'] = Role::where('id', '=', $id)->first(); $show['permissions'] = Permission::all(); // 获取全部权限, 用来判断那些全选选中了 $permissions = DB::table('permission_role')->where('role_id', '=', $id)->get(); $show['selected_permissions'] = []; foreach ($permissions as $value) { $show['selected_permissions'][] = $value->permission_id; } $treeView = $this->getTreeView($show['permissions'], $show['selected_permissions']); return View('admin.role.edit', ['title' => '后台管理 - 修改角色', 'show' => $show, 'treeView' => array_values($treeView)]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $permission = Permission::where('id', '=', $id)->first(); if (empty($permission)) { return redirect()->to('/admin/menu/')->withErrors("删除失败"); } $permission->delete(); return redirect()->to('/admin/menu/')->withErrors("删除成功"); }