/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $technican = Technican::findOrFail($id); $technican->delete(); return redirect('technicans'); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { $repair = Repair::findOrFail($id); $repairin = $request->all(); $tech_arr = $request->input('technicans'); $repairin['tech_no'] = count($tech_arr); $repair->update($repairin); //loop throught technincans fields $part_arr = $request->input('part_id'); $qty_arr = $request->input('part_qty'); $repair->spare_parts()->detach(); foreach ($part_arr as $key => $part) { if ($part != 0) { $part_obj = SparePart::find($part); $rep_id = $repair->rep_id; $qty = $qty_arr[$key]; $part_obj->repair()->attach($rep_id, ['part_qty' => $qty]); } } $repair->technicans()->detach(); foreach ($tech_arr as $tech) { $tech_obj = Technican::find($tech); $tech_obj->repair()->attach($repair); } return redirect('maintainance/repairs'); }
public function finish(Request $request, $id) { $task = Task::findOrFail($id); $task->update(['task_status' => 'تمت']); $task_id = $task->task_id; $tech = $request->tech_id; $technican = Technican::findOrFail($tech); $technican->task()->attach($task_id); //attaching spare_parts $part_arr = $request->input('part_id'); $qty_arr = $request->input('part_qty'); foreach ($part_arr as $key => $part) { if ($part != 0) { $part_obj = SparePart::find($part); $qty = $qty_arr[$key]; $part_obj->task()->attach($task_id, ['part_qty' => $qty]); } } return redirect('maintainance/tasks'); }