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(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $gallery = new Gallery(); $gallery->name = Request::input('name'); $gallery->slug = preg_replace("/[^a-zA-Z0-9 ]+/", "", $gallery->name); $gallery->slug = str_replace(' ', '-', $gallery->slug); $gallery->slug = strtolower($gallery->slug); $gallery->save(); $locations = Location::all(); $current = Location::current(); foreach ($locations as $location) { $locationGallery = new LocationGallery(); $locationGallery->gallery()->associate($gallery); $locationGallery->location()->associate($location); if ($location == $current) { $locationGallery->show = true; } $locationGallery->save(); } return $gallery; }