コード例 #1
0
 /**
  * Persist a journey post
  *
  * @return Illuminate\Http\Response
  */
 protected function persist()
 {
     // Write the body to the filesystem
     $bodyFilename = md5(uniqid(rand(), true)) . '.html';
     $bodyPath = base_path() . '/public/assets/journeys/descriptions/' . $bodyFilename;
     $bodyFile = fopen($bodyPath, 'w+');
     fwrite($bodyFile, htmlspecialchars(Input::get('body')));
     fclose($bodyFile);
     // Save the uploaded header image to
     // the filesystem if there was one
     if (Input::hasFile('header_image')) {
         $headerImageFilename = md5(uniqid(rand(), true)) . '.jpg';
         $headerImagePath = base_path() . '/public/assets/journeys/header_images/';
         Input::file('header_image')->move($headerImagePath, $headerImageFilename);
     }
     // Add the image path if
     // an image was uploaded
     $journeyData = ['traveler' => Auth::id(), 'title' => Input::get('title'), 'date' => Input::get('date'), 'description_filename' => $bodyFilename, 'created_at' => gmdate('Y-m-d H:i:s'), 'updated_at' => gmdate('Y-m-d H:i:s')];
     // Set the 'header_image_filename' to
     // NULL if the user hasn't uploaded
     // a header image with the post
     //
     $headerImageFilename = Input::hasFile('header_image') ? $headerImageFilename : NULL;
     // Send it to the database
     $journeyData += ['header_image_filename' => $headerImageFilename];
     // Persist the record to the database
     $created = Journey::create($journeyData);
     if ($created) {
         // Save the tag associations
         $this->persistTagsToJourneyWithID(Input::get('tags'), $created->id);
     }
     return redirect('/journeys');
 }