Skip to content

Instantly share code, notes, and snippets.

@caitlindaily
Last active August 29, 2015 14:03
Show Gist options
  • Save caitlindaily/c37c1c118b8b8632f6e8 to your computer and use it in GitHub Desktop.
Save caitlindaily/c37c1c118b8b8632f6e8 to your computer and use it in GitHub Desktop.
Uploading images
//Creating path and directory for files to live--will live under public dir and then the name we give the next dir
//To make image name unique, apply post id to the image's origianl name //--> public/img-upload/
//Need to move newly named image into image dir that was created
//defines the image path. this is used when wanting to display image. ex:--> show.blade.php <img src="{{{ $post->img_path }}}"
public function addUploadedImage ($image)
{
$systemPath = public_path() . '/' . $this->imgDir . '/';
$imageName = $this->id . '-' . $image->getClientOriginalName();//--> 2-image.jpg
$image->move($systemPath, $imageName);
$this->img_path = '/' . $this->imgDir . '/' . $imageName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment