/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $projects = Project::join('project_resident', 'project_resident.project_id', '=', 'projects.id')->join('residents', 'residents.id', '=', 'project_resident.resident_id')->where('residents.id', '=', Auth::user()->id)->get(['projects.*']); $etapas = stage::all(); return view('residente.avance', compact('projects', 'etapas')); }
/** * 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]); }