/** * 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'); }
public static function create(Url $url, $response) { $webpage = Webpage::where('Url', (string) $url)->first(); if (!$webpage) { return; } // dd( $webpage ); $statusCode = $response ? $response->getStatusCode() : self::UNRESPONSIVE_HOST; $html = ''; if (self::isHtml($response)) { $html = $response->getBody()->getContents(); $html = FilterContent::make($html); } Snapshot::create(['html' => $html, 'status_code' => $statusCode, 'webpage_id' => $webpage->id, 'hash' => md5($html)]); }