public function destroy($id)
 {
     $sampling = Sampling::findOrFail($id);
     $sampling->delete($id);
     Session::flash('message', 'Fue eliminado de nuestros registros.');
     return redirect()->route('muestras.index');
 }
 public function edit($id)
 {
     $view = Auth::user()->getView();
     $parameters = Parameter::all();
     $samplings = Sampling::all();
     $record = Record::findOrFail($id);
     return view('records.edit', compact('record', 'parameters', 'samplings', 'view'));
 }
 public function updateSampling($id, $muestrasId)
 {
     // var_dump($muestrasId);
     //die();
     foreach ($muestrasId as $key => $value) {
         $sampling = Sampling::findOrFail($value);
         $sampling->analysis_id = $id;
         $sampling->save();
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int $productId
  * @param Requests\ShowingSamplingsRequest $request
  * @return \Illuminate\Http\Response
  */
 public function show($productId, ShowingSamplingsRequest $request)
 {
     Product::findOrFail($productId);
     // Just to throw a failure if the product is not found
     $samplingsQueryBuilder = Sampling::query();
     $samplingsQueryBuilder->join('sensors', 'samplings.sensor_id', '=', 'sensors.id');
     $samplingsQueryBuilder->join('products', 'sensors.product_id', '=', 'products.id');
     $samplingsQueryBuilder->where('products.id', $productId);
     $limit = $request->has('limit') && $request->limit < 1000 ? $request->limit : 1000;
     $timeFiltersApplied = $this->filterResultsInTime($samplingsQueryBuilder, $request);
     if (!$timeFiltersApplied) {
         $samplingsQueryBuilder->whereDate('samplings.created_at', '=', Carbon::today()->toDateString());
     }
     if ($request->generic_sensor_id) {
         $samplingsQueryBuilder->join('generic_sensors', 'sensors.generic_sensor_id', '=', 'generic_sensors.id');
         $samplingsQueryBuilder->where('generic_sensors.id', $request->generic_sensor_id);
     }
     $samplingsQueryBuilder->orderBy('samplings.created_at', 'desc');
     $samplingsQueryBuilder->take($limit);
     return $samplingsQueryBuilder->get(array('samplings.id', 'samplings.sensor_id', 'samplings.sampled', 'samplings.created_at'));
 }
 /**
  * Display the specified resource.
  *
  * @param  int $productId
  * @param Requests\ShowingSamplingsRequest $request
  * @return \Illuminate\Http\Response
  */
 public function show($productId, ShowingSamplingsRequest $request)
 {
     $product = Product::join('locations', 'locations.product_id', '=', 'products.id')->where('locations.user_id', $this->guard->user()->getKey())->findOrFail($productId);
     // Just to throw a failure if the product is not found
     $samplingsQueryBuilder = Sampling::query();
     $samplingsQueryBuilder->join('sensors', 'samplings.sensor_id', '=', 'sensors.id');
     $samplingsQueryBuilder->join('generic_sensors', 'sensors.generic_sensor_id', '=', 'generic_sensors.id');
     $samplingsQueryBuilder->join('products', 'sensors.product_id', '=', 'products.id');
     $samplingsQueryBuilder->where('products.id', $productId);
     $samplingsQueryBuilder->orderBy('samplings.created_at', 'desc');
     $limit = $request->has('limit') && $request->limit < 1000 ? $request->limit : 1000;
     if ($request->generic_sensor_id) {
         $samplingsQueryBuilder->where('generic_sensors.id', $request->generic_sensor_id);
     }
     $timeFiltersApplied = $this->filterResultsInTime($samplingsQueryBuilder, $request, $product);
     if (!$timeFiltersApplied) {
         $samplingsQueryBuilder->whereDate('samplings.created_at', '=', Carbon::today()->toDateString());
     }
     $samplingsQueryBuilder->take($limit);
     //        if ($timeFiltersApplied && array_has(["week", "month", "year"], $request->timeFilter)) {
     //            return $samplingsQueryBuilder->selectRaw("
     //                samplings.sensor_id,
     //                max(samplings.sampled),
     //                generic_sensors.id as generic_sensor_id,
     //                min(samplings.created_at)
     //            ");
     //        }
     return $samplingsQueryBuilder->get(array('samplings.id', 'samplings.sensor_id', 'generic_sensors.id as generic_sensor_id', 'samplings.sampled', 'samplings.created_at'));
 }