/**
  * Save a new snapshot.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $snapshotUrl = $request->file('snapshot_url');
     if ($snapshotUrl) {
         $filename = time() . '.' . $snapshotUrl->getClientOriginalExtension();
         $filepath = '/snapshots/' . $filename;
         if (!Storage::disk('s3')->put($filepath, file_get_contents($snapshotUrl), 'public')) {
             $filename = '';
         }
     }
     $this->validate($request, ['store_id' => 'required']);
     if (!$request->id) {
         $snapshot = Snapshot::create(['store_id' => $request->store_id, 'notes' => $request->notes, 'snapshot_url' => isset($filepath) ? $filepath : '']);
     } else {
         $snapshot = Snapshot::find($request->id);
         $snapshot->store_id = $request->store_id;
         $snapshot->notes = $request->notes;
         if ($snapshotUrl) {
             $snapshot->snapshot_url = $filepath;
         }
         $snapshot->save();
     }
     $for_sale = Product::orderBy('name')->where('store_id', $request->store_id)->where('product_status', 1)->get();
     foreach ($for_sale as $item) {
         $snapshot->products()->attach($item->id);
     }
     return redirect('/snapshot');
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $snapshot = Snapshot::find($id);
     if ($snapshot['item_status'] == 'ready') {
         return view('snapshot.show', compact('snapshot'));
     }
     return view('snapshot.pending', compact('snapshot'));
 }