示例#1
0
 /**
  *
  */
 public static function showPropertyValue($model)
 {
     $properties = self::getPropertyByModel($model);
     $propertyValues = array();
     foreach ($properties as $property) {
         if ($property->type == "date") {
             $res = DateProperty::where('property_id', '=', $property->id)->where('element_id', "=", $model->id)->first();
         } else {
             $res = \App\PropertyValue::where('property_id', '=', $property->id)->where('element_id', "=", $model->id)->first();
         }
         if (!empty($res)) {
             $propertyValues[$property->id] = ['title' => $property->title, 'value' => $res->value, 'code' => $property->code, 'type' => $property->type];
         }
     }
     return $propertyValues;
 }
示例#2
0
 /**
  * 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}");
 }