roles->pluck('name','name')->all(); $checkeds = $role->permissions->pluck('id')->toArray(); return view('settings.role.edit', compact('role', 'permissions', 'checkeds')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Role $role * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $this->validate(request(), [ 'name' => 'required' ]); $role = Role::findOrFail($id); $role->update($request->except('permissions')); $permissions = $request->input('permissions') ? $request->input('permissions') : []; //$role->syncPermissions($permissions); if (isset($permissions)) { $role->permissions()->sync($permissions);//If one or more role is selected associate user to roles } else { $role->permissions()->detach(); //If no role is selected remove exisiting role associated to a user } return redirect()->route('role.index') ->with('flash_message', 'Role successfully edited.'); } /** * Remove the specified resource from storage. * * @param \App\Role $role * @return \Illuminate\Http\Response */ public function destroy(Role $role) { // } }