public function getPicture($id)
 {
     $picture = Picture::findOrFail($id);
     $path = storage_path('app/pictures/pic_' . $picture->id);
     $response = Response::make(File::get($path));
     $response->header('Content-Type', 'image/png');
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Get all Trips from user that allready started sorted by end-date (desc)
  *
  * @return mixed
  */
 public function getTripsForMyTrips()
 {
     $trips = $this->trips()->latest('end')->alreadyStarted()->get();
     //retrieving path of featured images
     foreach ($trips as $trip) {
         if ($trip['pic']) {
             $pic = Picture::findOrFail($trip['pic']);
             $trip['picName'] = $pic->filename;
         }
     }
     return $trips;
 }
Ejemplo n.º 3
0
 /**
  * returns Picture with prev and next Picture as attributes for single navigation
  *
  * @param $id
  * @return mixed
  */
 public static function getSinglePic($id)
 {
     $pic = Picture::findOrFail($id);
     $all = Picture::where('trip_entry_id', $pic->trip_entry_id)->orderBy('id')->get();
     $index = $all->search($pic);
     $count = $all->count();
     if ($index != 0) {
         $prev = $all[$index - 1];
         $pic->prev = $prev;
     }
     if ($index + 1 != $count) {
         $next = $all[$index + 1];
         $pic->next = $next;
     }
     return $pic;
 }
 /**
  * Implements picture like and dislike (voting). Ensures that user is
  * allowed to vote by checking database records.
  *
  * parameter:   http-request
  * returns:     vote success in json-format (also possible return trough
  *              validation error)
  */
 public function votePicture(Request $request)
 {
     // May cause early return with error condition in json-format.
     $this->validate($request, ['picture_id' => 'required|integer|exists:pictures,id', 'operation' => 'required|min:4|max:7']);
     $pictureVotes = PictureVotes::where('user_id', Auth::user()->id)->where('picture_id', $request->picture_id)->get();
     if ($pictureVotes->count() > 0) {
         // User has voted on this picture before.
         $isSuccessful = false;
     } else {
         // A fresh vote.
         $picture = Picture::findOrFail($request->picture_id);
         $isSuccessful = true;
         if ($request->operation == 'like') {
             $picture->likes = $picture->likes + 1;
         } else {
             $picture->dislikes = $picture->dislikes + 1;
         }
         $picture->save();
         // Database insert into pictures-table.
         // Store new picture vote into database.
         $pictureVotes = new PictureVotes();
         $pictureVotes->user_id = Auth::user()->id;
         $pictureVotes->picture_id = $request->picture_id;
         $pictureVotes->voted = true;
         // Not needed
         $pictureVotes->vote_type = $request->operation;
         $pictureVotes->save();
         // Database insert into picture_votes-table.
     }
     return response()->json(['is_successful' => $isSuccessful]);
 }
Ejemplo n.º 5
0
 /**
  * get all entries associated with a trip containing the filename for the featured image of the entry
  *
  * @return mixed
  */
 public function getEntriesWithPic()
 {
     $entries = $this->tripEntries()->get();
     //retrieving path of featured images
     foreach ($entries as $entry) {
         if ($entry['pic']) {
             $pic = Picture::findOrFail($entry['pic']);
             $entry['picName'] = $pic->filename;
         }
     }
     return $entries;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $offer = Offer::findOrFail($id)->isOwnedOrFail();
     $this->validate($request, $this->getValidation());
     $offer->update($request->all());
     $keepPictures = $request->input('keep_pictures', []);
     $pictures = $offer->pictures()->lists('id');
     foreach ($pictures->diff($keepPictures) as $pictureId) {
         $picture = Picture::findOrFail($pictureId);
         unlink(storage_path('app/pictures/pic_' . $picture->id));
         $picture->delete();
     }
     foreach ($request->file('pictures', []) as $file) {
         if (!$file) {
             break;
         }
         $picture = new Picture();
         $picture->extension = $file->getClientOriginalExtension();
         $offer->pictures()->save($picture);
         $file->move(storage_path('app/pictures'), 'pic_' . $picture->id);
     }
     return redirect('host/offers');
 }
Ejemplo n.º 7
0
 /**
  * Remove the specified resource from storage.
  *
  * @param $trip_id
  * @param $entry_id
  * @param $pic_id
  * @return Response
  * @internal param int $id
  */
 public function destroy($trip_id, $entry_id, $pic_id)
 {
     $pic = Picture::findOrFail($pic_id);
     $trip = Trip::findOrFail($trip_id);
     $entry = TripEntry::findOrFail($entry_id);
     $user = Auth::user();
     if (Auth::user()->id == $trip->user_id && $trip->id == $entry->trip_id && $pic->trip_entry_id == $entry->id) {
         $pic->deleteWithImage($user->id);
         return redirect(url('trip') . '/' . $trip_id . '/entry/' . $entry->id);
     } else {
         return 'You are not authorized to delete this picture!';
     }
 }
 public function deletePicture($id, $picture)
 {
     $gallery = Gallery::findOrFail($id);
     $pictureDB = Picture::findOrFail($picture);
     unlink(base_path() . '/public/images/galleries/' . $gallery->id . '/' . $pictureDB->picture);
     Picture::destroy($picture);
     return redirect(route('admin.galleries.editPictures', $gallery))->with('success', 'L\'image a bien été supprimée');
 }