public function add(Request $request) { $user = \Session::get('user'); if (!$user->can('项目硬件部署管理')) { abort(401); } $item = new HardwareItem(); $project = Project::find($request->input('project_id')); $hardware = Hardware::find($request->input('hardware_id')); $item->hardware()->associate($hardware); $item->project()->associate($project); $item->ref_no = $request->input('ref_no'); $item->status = $request->input('status'); $item->extra = $request->input('fields', []); $time = $request->input('time'); if (!$time) { $time = null; } else { $time = \Carbon\Carbon::createFromFormat('Y/m/d', $time)->format('Y-m-d H:i:s'); } $item->time = $time; $item->save(); Clog::add($project, '硬件明细添加', [strtr('添加硬件 (%hardware_name) 下新的硬件明细 [%item_id]', ['%hardware_name' => $hardware->name, '%item_id' => $item->id])], Clog::LEVEL_NOTICE); \Log::notice(strtr('项目硬件明细增加: 用户(%name[%id]) 添加了项目(%project_name[%project_id]) 硬件 (%hardware_name[%hardware_id]) 的 明细信息: %hardware_item_id', ['%name' => $user->name, '%id' => $user->id, '%project_name' => $project->name, '%project_id' => $project->id, '%hardware_name' => $hardware->name, '%hardware_id' => $hardware->id, '%hardware_item_id' => $item->id])); return redirect()->to(route('project.profile', ['id' => $project->id]))->with('message_type', 'info')->with('message_content', '添加部署硬件成功!')->with('tab', 'hardwares'); }
public function add(Request $request) { $field = new HardwareField(); $field->name = $request->input('name'); $hardware = Hardware::find($request->input('hardware_id')); $field->hardware()->associate($hardware); $field->save(); return redirect()->to(route('hardware.profile', ['id' => $hardware->id]))->with('message_content', '添加成功!')->with('message_type', 'info'); }
public function hardware_edit($id, Request $request) { $user = \Session::get('user'); if (!$user->can('项目硬件管理')) { abort(401); } $hardware_id = $request->input('hardware_id'); $hardware = Hardware::find($hardware_id); $project = Project::find($id); $h = $project->hardwares()->where('hardware_id', $hardware_id)->first(); $old = ['description' => $h->pivot->description, 'count' => $h->pivot->count]; $new = ['description' => $request->input('description'), 'count' => $request->input('count')]; $project->hardwares()->detach($hardware_id); $project->hardwares()->save($hardware, $new); $change = []; $diff_helper = ['description' => '描述', 'count' => '计划部署数量']; foreach (array_keys($diff_helper) as $item) { if ($old[$item] != $new[$item]) { $change[] = ['old' => $old[$item], 'new' => $new[$item], 'title' => $diff_helper[$item]]; } } if (count($change)) { foreach ($change as $c) { \Log::notice(strtr('项目关联硬件信息修改: 用户(%name[%id]) 修改了项目(%project_name[%project_id]) 关联硬件的信息: %title %old -> %new', ['%name' => $user->name, '%id' => $user->id, '%project_name' => $project->name, '%project_id' => $project->id, '%title' => $c['title'], '%old' => $c['old'], '%new' => $c['new']])); } array_unshift($change, ['title' => strtr('项目硬件: %hardware_name', ['%hardware_name' => $hardware->name])]); Clog::add($project, '关联硬件基本信息修改', $change, Clog::LEVEL_WARNING); } return redirect()->back()->with('message_content', '硬件修改成功!')->with('message_type', 'info')->with('tab', 'hardwares'); }
public function hardwares_json() { return response()->json(Hardware::all()); }