Skip to content

Instantly share code, notes, and snippets.

@mishajib
Created August 14, 2021 19:46
Show Gist options
  • Save mishajib/cf632f7ab728c81706598af46c3633b8 to your computer and use it in GitHub Desktop.
Save mishajib/cf632f7ab728c81706598af46c3633b8 to your computer and use it in GitHub Desktop.
Larave helper for image upload
function imageUploadHandler($image, $request_path = 'default', $size = null, $old_image = null)
{
if (isset($old_image)) {
if (Storage::disk('public')->exists($old_image)) {
Storage::disk('public')->delete($old_image);
}
}
$path = $image->store($request_path, 'public');
if (isset($size)) {
$request_size = explode('x', $size);
$width = $request_size[0];
$height = $request_size[1];
} else {
$width = 80;
$height = 80;
}
$image = Image::make(Storage::disk('public')->get($path))->fit($width, $height)->encode();
Storage::disk('public')->put($path, $image);
return $path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment