/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $design = Desing::find($id);
     $stages = Activity_Stage::where('activity_stage.design_id', '=', $design->id)->get(['activity_stage.*']);
     return response()->json($stages);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function actualizar(Request $request)
 {
     $data = $request->all();
     $change = Activity_Stage::where('activity_id', '=', $data['activity_id'])->where('stage_project_id', '=', $data['stage_project_id'])->first();
     $change->fill($data);
     $change->material = $data['material'];
     $change->save();
     $project = Project::join('project_stage', 'project_stage.project_id', '=', 'projects.id')->join('activity_stage', 'activity_stage.stage_project_id', '=', 'project_stage.id')->where('project_stage.id', '=', $data['stage_project_id'])->get(['projects.*']);
     $project = Project::find($project->first()->id);
     $all = Activity_Stage::join('project_stage', 'project_stage.id', '=', 'activity_stage.stage_project_id')->join('projects', 'projects.id', '=', 'project_stage.project_id')->where('projects.id', '=', $project->id)->get(['activity_stage.*']);
     $valor_total = 0;
     foreach ($all as $a) {
         $valor = 0;
         $valor += $a->hand + $a->transport + $a->material;
         $valor_total += $valor * $a->quantity;
     }
     $project->budget = $valor_total;
     $project->save();
     return response()->json([$all]);
 }