/**
  * Update the specified department in storage.
  */
 public function update($id)
 {
     $department = Department::findOrFail($id);
     $validator = Validator::make($input = Input::all(), Department::rules($id));
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $department->update(['deptName' => $input['deptName']]);
     foreach ($input['designation'] as $index => $value) {
         if ($value == '' && !isset($input['designationID'][$index])) {
             continue;
         }
         if (isset($input['designationID'][$index])) {
             if ($value == '') {
                 Designation::destroy($input['designationID'][$index]);
             } else {
                 $design = Designation::find($input['designationID'][$index]);
                 $design->designation = $value;
                 $design->save();
             }
         } else {
             Designation::firstOrCreate(['deptID' => $department->id, 'designation' => $value]);
         }
     }
     return Redirect::route('admin.departments.index')->with('success', "<strong>{$input['deptName']}</strong>  Actualizado correctamente");
 }
Example #2
0
 /**
  * Update the specified department in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $department = Department::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Department::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $department->update($data);
     return Redirect::route('admin.departments.index');
 }
 public function update($id)
 {
     Auth::isAdminOrDie(App::$instance);
     Token::checkToken();
     $request = $this->request->request;
     $this->validator->validate(['Префикс' => [$request->get('prefix'), 'required|int'], 'Название' => [$request->get('name'), 'required|max(255)']]);
     //if no passes
     if (!$this->validator->passes()) {
         App::$instance->MQ->setMessage($this->validator->errors()->all());
         ST::redirect("back");
     }
     $dep = Department::findOrFail($id);
     $dep->fill($request->all());
     $dep->save();
     App::$instance->MQ->setMessage("Успешно отредактировано");
     App::$instance->log->logWrite(LOG_CONFIG_CHANGE, 'Подразделение отредактировано' . $dep->name);
     ST::redirectToRoute('Departments/index');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $del = \Department::findOrFail($id);
     if ($del->delete()) {
         return \Redirect::back()->with('success', 'Successfully deleted');
     }
 }