public function store(Request $request) { $communityId = $request->get('community_id'); $galleryInstance = Gallery\GalleryInstance::where('community_id', '=', $communityId)->where('gallery_id', '=', 1)->first(); if (is_null($galleryInstance)) { $galleryInstance = new Gallery\GalleryInstance(); $galleryInstance->gallery_id = 1; $galleryInstance->community_id = $communityId; $galleryInstance->save(); } //create upload dir $fileArr = explode('.', $_FILES['image']['name']); $fileName = str_replace(' ', '', $fileArr[0]) . uniqid() . '.' . $fileArr[count($fileArr) - 1]; $uploadDir = 'uploads/galleryInstances/' . $galleryInstance->id; if (!file_exists($uploadDir)) { mkdir($uploadDir); } // Database record $galleryItem = new Gallery\GalleryItem(); $galleryItem->gallery_instance_id = $galleryInstance->id; $galleryItem->filename = $fileName; if ($galleryItem->save()) { move_uploaded_file($_FILES['image']['tmp_name'], $uploadDir . '/' . $fileName); } return $galleryInstance->items; }
protected function setParams() { $galleryInstance = \App\RExpress\Models\Gallery\GalleryInstance::where('gallery_id', '=', $this->options['galleryId'])->where('community_id', '=', $this->community->iCommunityId)->first(); if (is_object($galleryInstance)) { $galleryItems = \App\RExpress\Models\Gallery\GalleryItem::where('gallery_instance_id', '=', $galleryInstance->id)->get(); $this->params = ['community' => $this->community, 'options' => $this->options, 'galleryInstanceId' => $galleryInstance->id, 'galleryItems' => $galleryItems]; } else { $this->params = ['community' => $this->community, 'options' => $this->options, 'galleryInstanceId' => '', 'galleryItems' => []]; } }
public function destroy($id, Responder $responder) { $item = \App\RExpress\Models\Gallery\GalleryItem::find($id); if (!$item->delete()) { $responder->fails = true; $responder->messages = ['DB', 'Problem deleting record from database']; return $responder->json(); } $uploadDir = 'uploads/galleryInstances/' . $item->gallery_instance_id . '/' . $item->filename; unlink($uploadDir); return $responder->json(); }