Skip to content

Instantly share code, notes, and snippets.

@fuale
Created July 17, 2018 18:04
Show Gist options
  • Save fuale/8721a5b732f53d8e238f90da93eb4ab3 to your computer and use it in GitHub Desktop.
Save fuale/8721a5b732f53d8e238f90da93eb4ab3 to your computer and use it in GitHub Desktop.
<?php
/* Laravel 5.6 */
/**
* model
* Upload image
*/
/*----- Don't use -----*/
function photo($file)
{
$directory = '/image';
$destinationPath = public_path() . $directory;
$filename = str_random(20) . '.jpg';
$output = $directory . '/' . $filename;
$file->move($destinationPath, $filename);
return $output;
}
/*------ Use this ------*/
function uploadImage($file)
{
return $this->storage::url(
$this->storage::disk('public')
->put('image', $file, 'public')
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment