Exemplo n.º 1
0
 /**
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param \HorseStories\Models\Horses\Horse $horse
  * @param bool $profile
  * @return \HorseStories\Models\Pictures\Picture
  */
 public function uploadPicture($file, $horse, $profile = false)
 {
     $extension = $file->getClientOriginalExtension();
     $path = '/uploads/pictures/' . $horse->id;
     $fileName = str_random(12);
     $pathToFile = storage_path() . '/app' . $path . '/' . $fileName . '.' . $extension;
     $picture = new Picture();
     $picture->path = $fileName . '.' . $extension;
     $picture->horse_id = $horse->id;
     $picture->mime = $file->getClientMimeType();
     $picture->original_name = $file->getClientOriginalName();
     $picture->profile_pic = $profile;
     $picture->save();
     if (!file_exists(storage_path() . $path)) {
         $this->file->makeDirectory($path);
     }
     $this->image->make($file->getrealpath())->resize(null, 350, function ($constraints) {
         $constraints->aspectRatio();
     })->save($pathToFile);
     return $picture;
 }
 public function checkDeletedDir(Filesystem $storage)
 {
     return $storage->exists("uploads/photos/deleted/") || $storage->makeDirectory("uploads/photos/deleted/");
 }