private function operating($target, $type, $method)
 {
     $targetObject = $type == User::INVOLVED_WORK_ORDER ? WorkOrder::findOrFail($target) : Group::findOrFail($target);
     $operator = \Auth::user()->involvements($type);
     if ($method) {
         $operator->attach($targetObject->id);
     } else {
         $operator->detach($targetObject->id);
     }
     if (\Request::ajax()) {
         return response()->json(['body' => 'success']);
     }
     return redirect()->back();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = \Validator::make($request->all(), ['subject' => 'required', 'sort' => 'required|numeric|min:0|max:5', 'content' => 'required', 'category_id' => 'required|exists:categories,id', 'group_id' => 'required|exists:groups,id']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator->errors());
     }
     return \DB::transaction(function () use($request) {
         $group = Group::findOrFail($request->input('group_id'));
         $category = Category::findOrFail($request->input('category_id'));
         $workOrder = new WorkOrder();
         $workOrder->subject = $request->input('subject');
         $workOrder->sort = $request->input('sort');
         $workOrder->category()->associate($category);
         $workOrder->group()->associate($group);
         $workOrder->publisher()->associate(\Auth::user());
         $workOrder->save();
         return redirect()->route('host.work.work-order.show', $workOrder->id)->with('create-success', 'work-order');
     });
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int                      $id
  *
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $validator = \Validator::make($request->all(), ['display_name' => 'required']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator->errors());
     }
     $group = Group::findOrFail($id);
     $group->display_name = $request->input('display_name');
     $group->description = $request->input('description', '');
     $group->save();
     return redirect()->back()->with('update-success', 'group');
 }