get(); return view('admin/rolecreate', ['permissions' => $permissions]); } /** * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function store(Request $request) { $this->validate($request, [ 'name' => 'unique:role|required', 'permissions' => 'required' ],[ 'name.required' => '角色名称不能为空', 'name.unique' => '角色名称已经存在', 'permissions.required' => '该角色权限不能为空', ]); $childs= $request->input('permissions'); foreach($childs as $a){ $role = new Role(); $role->name = $request->input('name'); $role->child = $a; $role->create_time = time(); $role->save(); } return redirect('/admin/permission/index?type=2')->with('info', '添加角色成功'); } /** * @param $name * @return \Illuminate\View\View */ public function edit($name) { $data['role'] = $name; $data['role_permissions'] = Role::select('child')->where('name', '=', $name)->get(); $permissions = Permission::select('id','name','description','parent_id')->get(); return view('admin/roleedit', ['permissions' => $permissions, 'data' => $data]); } /** * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function update(Request $request) { $this->validate($request, [ 'permissions' => 'required' ],[ 'permissions.required' => '该角色权限不能为空', ]); $childs= $request->input('permissions'); Role::where('name', '=', $request->input('name'))->delete(); foreach($childs as $a){ $role = new Role(); $role->name = $request->input('name'); $role->child = $a; $role->create_time = time(); $role->save(); } return redirect('/admin/permission/index?type=2')->with('info', '修改角色成功'); } }