Esempio n. 1
0
 public function savePhoto($photo, $type, $sort_order = 0)
 {
     $propertyAttachment = new PropertyAttachment();
     if ($type == 'photo') {
         $uploadPath = $propertyAttachment::$photosUploadPath;
     } elseif ($type == 'floorplan') {
         $uploadPath = $propertyAttachment::$floorplanUploadPath;
     }
     $prefix = $this->id . '_' . time();
     $fileName = $prefix . '.' . $photo->getClientOriginalExtension();
     $duplicateCount = 0;
     while (Storage::disk('local')->exists($uploadPath . '/original/' . $fileName)) {
         $duplicateCount += 1;
         $fileName = $prefix . ($duplicateCount + 1) . '.' . $photo->getClientOriginalExtension();
     }
     Storage::disk('local')->put($uploadPath . '/original/' . $fileName, File::get($photo));
     $propertyAttachment->fill(['title' => filter_var($photo->getClientOriginalName(), FILTER_SANITIZE_STRING), 'filename' => $fileName, 'sort_order' => $sort_order, 'type' => $type]);
     $propertyAttachment->property()->associate($this);
     $propertyAttachment->save();
     $propertyAttachment->resize();
     return $propertyAttachment;
 }