private function processImage($image, $galleryName) { $gallery = null; if (!in_array($galleryName, $this->galleries)) { // Create gallery (or attempt to) $gallery = new Gallery(); $gallery->name = $galleryName; $gallery->save(); foreach ($this->locations as $location) { $locationGallery = new LocationGallery(); $locationGallery->gallery()->associate($gallery); $locationGallery->location()->associate($location); $locationGallery->show = true; $locationGallery->save(); } array_push($this->galleries, $galleryName); } if ($gallery == null) { $gallery = Gallery::where('name', $galleryName)->first(); } // "Upload" the image $filename = substr($image, strrpos($image, '/') + 1); $imgExt = strtolower(substr($filename, strrpos($filename, '.') + 1)); $imgMime = $imgExt == 'jpg' || $imgExt == 'jpeg' ? 'image/jpeg' : 'image/png'; $fileSize = filesize($image); copy($image, $this->dirname . '/' . $filename); $file = new UploadedFile($this->dirname . '/' . $filename, $filename, $imgMime, $fileSize, null, true); $uploadedImage = ImageList::upload($file); // Attach the image to the gallery $gallery->images()->save($uploadedImage); $gallery->save(); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // Mark the gallery as hidden for this location $locationGallery = LocationGallery::where('gallery_id', '=', $id)->where('location_id', '=', Location::current()->id)->first(); $locationGallery->show = false; $locationGallery->save(); return Response::json('success', 200); }