public function approve($id)
 {
     $tracking = $this->trackingRepository->findWithoutFail($id);
     if (empty($tracking)) {
         Flash::error('Tracking not found');
         return back();
     }
     $this->trackingRepository->update(["state" => "Inserted"], $id);
     Flash::success('Tracking approved!');
     return back();
 }
 /**
  * Update the specified Tracking in storage.
  *
  * @param  int              $location_id
  * @param  int              $tracking_id
  * @param UpdateTrackingRequest $request
  *
  * @return Response
  */
 public function update($location_id, $tracking_id, UpdateTrackingRequest $request)
 {
     $tracking = $this->trackingRepository->findWithoutFail($tracking_id);
     if (empty($tracking)) {
         Flash::error('Tracking not found');
         return redirect(route('inserter.locations.trackings.index', $location_id));
     }
     if ($tracking->inserted_at && $tracking->inserted_at->diffInMinutes(Carbon::now()) > 10) {
         Flash::error('Trackings are only editable within 10 minutes after insertion.');
         return redirect(route('inserter.locations.trackings.index', $location_id));
     }
     $different_campaign = $request->input('different_campaign', 0);
     $user_id = $request->user()->id;
     $keys = [];
     if ($request->has('tracking_state')) {
         switch ($request->tracking_state) {
             case 'regular_billboard':
                 $brand_id = $request->brand_id;
                 $product_id = $request->product_id;
                 $brand = $this->brandRepository->findWithoutFail($brand_id);
                 $product = $this->productRepository->findWithoutFail($product_id);
                 if (!$brand || !$product || $brand->industry_id != $product->subindustry->industry_id) {
                     Flash::error('There is no relation between the selected brand and the product');
                     return redirect(route('inserter.locations.trackings.index', $location_id));
                 }
                 $pending_approval = $brand->isPendingApproval() || $product->isPendingApproval();
                 $keys = ['different_campaign' => $different_campaign, 'brand_id' => $brand_id, 'product_id' => $product_id, 'state' => $pending_approval ? 'Pending approval' : 'Inserted', 'user_id' => $user_id];
                 break;
             case 'empty_billboard':
                 $keys = ['different_campaign' => null, 'brand_id' => null, 'product_id' => null, 'state' => 'Inserted', 'user_id' => $user_id];
                 break;
             case 'something_wrong':
                 $keys = ['different_campaign' => null, 'brand_id' => null, 'product_id' => null, 'state' => 'Something wrong', 'user_id' => $user_id];
                 break;
         }
     }
     $tracking = $this->trackingRepository->update($keys, $tracking_id);
     $nextId = $tracking->nextId($location_id);
     if ($nextId) {
         $route = route('inserter.locations.trackings.insert', [$location_id, 'tracking' => $nextId]);
     } else {
         $route = route('inserter.locations.trackings.index', $location_id);
     }
     Flash::success('Tracking updated successfully.');
     return redirect($route);
 }