/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Requests\CreateClaimRequest $request) { $request = $request->all(); $claim = Claim::findOrFail($id); $request['update_by'] = Auth::user()->id; $propertyList = array(); $errors = new Support\MessageBag(); if (isset($request["property"])) { $properties = Property::getPropertyByModel($claim); foreach ($properties as $property) { try { //if(isset($request["property"][$property->id])) //{ $attributes = ['value' => $request["property"][$property->id], 'property_id' => $property->id, 'element_id' => $claim->id]; if ($property->type == 'date') { $pr = PropertyTypes\DateProperty::where('property_id', $property->id)->where('element_id', $claim->id)->first(); //$pr->setPropertyTitle($property->title); if (empty($pr)) { $pr = new PropertyTypes\DateProperty($attributes, $property->title); } else { $pr->value = $attributes["value"]; } } elseif ($property->type == 'number') { $pr = PropertyTypes\NumberProperty::where('property_id', $property->id)->where('element_id', $claim->id)->first(); //$pr->setPropertyTitle($property->title); if (empty($pr)) { $pr = new PropertyTypes\NumberProperty($attributes, $property->title); } else { $pr->value = $attributes["value"]; } } else { $pr = PropertyTypes\TextProperty::where('property_id', $property->id)->where('element_id', $claim->id)->first(); //$pr->setPropertyTitle($property->title); if (empty($pr)) { $pr = new PropertyTypes\TextProperty($attributes, $property->title); } else { $pr->value = $attributes["value"]; } } //} $propertyList[] = $pr; } catch (ValidationException $e) { $errors->merge($e->errors()); } } } if ($errors->count() > 0) { return \Redirect::back()->withInput($request)->withErrors($errors); } $claim->update($request); foreach ($propertyList as $pr) { $pr->save(); } return redirect("claim/{$id}"); }