Ejemplo n.º 1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($idOrTitle)
 {
     if (is_numeric($idOrTitle)) {
         $note = Note::find($idOrTitle);
     } else {
         $note = Note::where('slug', '=', $idOrTitle)->first();
     }
     if (!$note) {
         App::abort(404);
     }
     if ($note->public_or_private == "private") {
         if (Auth::user()->id != $note->user_id) {
             Session::flash('errorMessage', 'This note is private and cannot be accessed publicly.');
             return Redirect::action('NotesController@index');
         }
     }
     $comments = [];
     $allcomments = Notecom::all();
     foreach ($allcomments as $comment) {
         if ($comment->note_id == $note->id) {
             $commentdata = array('created_at' => $comment->created_at, 'id' => $comment->id, 'comment' => $comment->comment, 'commenter' => $comment->collaborator_name);
             array_push($comments, $commentdata);
         }
     }
     return View::make('notes.show')->with(['note' => $note, 'hasVoted' => $note->userHasVoted()])->with('comments', $comments);
 }
 public function editcommentnote($id, $commentid)
 {
     $validator = Validator::make(Input::all(), Notecom::$rules);
     if ($validator->fails()) {
         Session::flash('errorMessage', 'Your input must be between 1 and 1000 characters');
         return Redirect::back()->withInput();
     } else {
         $commenttoupdate = Notecom::find($commentid);
         $note = $id;
         $commenttoupdate->comment = Input::get('comment');
         $commenttoupdate->save();
         Session::flash('successMessage', 'Input successfully updated!');
         return Redirect::action('NotesController@show', array($id));
     }
 }