コード例 #1
0
 public function photosRotate(Request $request, $id, $dir = 'right', $attachment_id)
 {
     $property = Property::withTrashed()->findOrFail($id);
     $this->attachmentBelongsToProperty($attachment_id, $property);
     $propertyAttachment = PropertyAttachment::findOrFail($attachment_id);
     $propertyAttachment->rotate($dir);
     if ($propertyAttachment->type == 'photo') {
         return redirect()->back()->with('messages', ['Photo has been rotated']);
     } elseif ($propertyAttachment->type == 'floorplan') {
         return redirect()->back()->with('messages', ['Floorplan has been rotated']);
     }
 }
コード例 #2
0
ファイル: Property.php プロジェクト: yohanes1989/goprop
 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;
 }
コード例 #3
0
 public function postPropertyPhotosReorder(Request $request, $id, $type)
 {
     $property = Property::findOrFail($id);
     $allowedAttachments = $property->attachments()->lists('id')->all();
     $count = 1;
     $ordered = [];
     foreach ($request->input('photos', []) as $photo) {
         if (in_array($photo, $allowedAttachments)) {
             $attachment = PropertyAttachment::findOrFail($photo);
             $attachment->update(['sort_order' => $count]);
             $ordered[] = $attachment->id;
             $count += 1;
         }
     }
     return response()->json($ordered);
 }