if ($url = $request->get('url')) {
$path = public_path(self::UPLOAD_PATH);
if(!is_dir($path)) {
File::makeDirectory($path, 0777, true, true);
}
$httpClient = new Client();
$response = $httpClient->get(
$url,
[
RequestOptions::SINK => $path,
]
);
if ($response->getStatusCode() === 200) {
$record = UploadImage::create([
'url' => $path,
]);
$url = config('app.url') .'/'. $record->url;
return response()->file(
$url,
['Content-Type' => 'image/png']
);
}
}