public function put($data, $id)
 {
     $obj = CakeRequest::find($id);
     if (@isset($data['delivery_timestamp']) && $data['delivery_timestamp'] != null) {
         $obj->delivery_timestamp = $data['delivery_timestamp'];
     }
     if (@isset($data['client_name']) && $data['client_name'] != null) {
         $obj->client_name = $data['client_name'];
     }
     if (@isset($data['client_phone']) && $data['client_phone'] != null) {
         $obj->client_phone = $data['client_phone'];
     }
     if (@isset($data['client_mobile']) && $data['client_mobile'] != null) {
         $obj->client_mobile = $data['client_mobile'];
     }
     if (@isset($data['estimated_price']) && $data['estimated_price'] != null) {
         $obj->estimated_price = $data['estimated_price'];
     }
     if (@isset($data['payment_value']) && $data['payment_value'] != null) {
         $obj->payment_value = $data['payment_value'];
     }
     if (@isset($data['status']) && $data['status'] != null) {
         $obj->status = $data['status'];
     }
     if (@isset($data['note']) && $data['note'] != null) {
         $obj->note = $data['note'];
     }
     return $obj;
 }
 public function deleteCakeImage(Request $request)
 {
     try {
         $cakeRequest = CakeRequest::find(intval($request->get('id')));
         $cakeRequest->cake_image = null;
         if ($cakeRequest->save()) {
             return response()->json(array('code' => 200, 'message' => 'success'), 200);
         } else {
             throw new \Exception('Não foi possível excluir esta imagem', 500);
         }
     } catch (\Exception $e) {
         return response()->json(array('code' => $e->getCode(), 'message' => $e->getMessage()), 500);
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     try {
         DB::beginTransaction();
         $request->merge(array('delivery_timestamp' => date('Y-m-d', strtotime(str_replace('/', '-', $request->get('delivery_timestamp'))))));
         if ($request->get('estimated_price') != null) {
             $request->merge(array('estimated_price' => doubleval(str_replace(',', '.', str_replace('.', '', $request->get('estimated_price'))))));
         }
         if ($request->get('payment_value') != null) {
             $request->merge(array('payment_value' => doubleval(str_replace(',', '.', str_replace('.', '', $request->get('payment_value'))))));
         }
         dd($request->all());
         $validator = (new CakeRequest())->validate($request->all());
         if ($validator->fails()) {
             throw new \Exception('Erro na validação dos dados', 500);
         }
         $cakeRequest = (new CakeRequest())->put($request->all(), $id);
         if (boolval($request->has('cake_image'))) {
             $urlCakeImage = CakeRequest::uploadCakeImage($request->file('cake_image'));
             if ($urlCakeImage != null) {
                 $cakeRequest->cake_image = $urlCakeImage;
             }
         }
         if (!$cakeRequest->save()) {
             throw new \Exception('Não foi possível salvar o pedido', 500);
         }
         DB::commit();
         return redirect('/admin/cake-requests/' . $id);
     } catch (\Exception $e) {
         DB::rollBack();
         dd($e);
         return redirect()->back();
     }
 }