/** * Post a single Edit Exhibit. */ public function postEditSingle() { // Validate form fields $id = Input::get('id'); $exhibit = Exhibit::find($id); $validator = Exhibit::makeEditValidator(Input::get('title'), Input::get('video')); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } // Validate images if they are present and ajax hasn't run if (Input::hasFile('file')) { $files = Input::file('file'); foreach ($files as $file) { $validator = Validator::make(array('file' => $file), array('file' => 'mimes:png,gif,jpeg|max:20000')); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } } } $created_at = strtotime(Input::get('created_at')); $created_at = date('Y-m-d H:i:s', $created_at); $user_id = Auth::user()->id; $cleanTitle = Exhibit::permalink(Input::get('title')); $exhibit->update(array('user_id' => $user_id, 'title' => Input::get('title'), 'permalink' => $cleanTitle, 'created_at' => $created_at, 'details' => Input::get('details'), 'video' => Input::get('video'), 'published' => (bool) Input::get('published'))); $exhibit->save(); if (Input::hasFile('file')) { foreach ($files as $file) { $currentMo = date('Y_M'); $destination = "uploads/{$currentMo}"; $filename = $file->getClientOriginalName(); $filename = Exhibit::string_convert($filename); // $cleanFilename = Exhibit::permalink($filename); // Move the new file into the uploads directory $uploadSuccess = $file->move($destination, "{$filename}"); $imgOrigDestination = $destination . '/' . $filename; // Check to make sure that upload was successful and add the content if ($uploadSuccess) { $imageMinDestination = $destination . '/min_' . $filename; $imageMin = Image::make($imgOrigDestination)->crop(250, 250, 10, 10)->save($imageMinDestination); // Saves the media and adds the appropriate foreign keys for the exhibit $media = $exhibit->media()->create(['user_id' => $user_id, 'img_min' => $imageMinDestination, 'img_big' => $imgOrigDestination]); $exhibit->media()->save($media); if (!$media) { return Redirect::back()->with('status', 'alert-danger')->with('global', 'Something went wrong with uploading your images. :/'); } } } } return Redirect::route('exhibits-show-single', $exhibit->permalink)->with('status', 'alert-success')->with('global', 'You have successfully updated ' . $exhibit->title . '.'); }