Created
August 14, 2021 19:46
-
-
Save mishajib/cf632f7ab728c81706598af46c3633b8 to your computer and use it in GitHub Desktop.
Larave helper for image upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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