Пример #1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $topic = Topic::find($id, ['id', 'title', 'user_id', 'ip', 'content', 'created_at']);
     $topic->load(['user' => function ($query) {
         $query->select('id', 'name');
     }]);
     $comments = Comment::withTrashed()->select('user_id', 'ip', 'content', 'deleted_at', 'created_at')->where('topic_id', $id)->orderBy('id')->paginate(100);
     $comments->load(['user' => function ($query) {
         $query->select('id', 'name');
     }]);
     return view('bbs.topic', ['topic' => $topic, 'comments' => $comments]);
 }
Пример #2
0
 public function restore($id)
 {
     $comment = Comment::withTrashed()->with('vote.user')->find($id);
     if (!$comment) {
         abort(404, 'Comment does not exist');
     }
     if ($comment->user->id != Auth::user()->id && !Auth::user()->can('administrate-comment')) {
         abort(401, 'User does not have permission to restore this comment');
     }
     $comment->deleted_at = null;
     //restore() isn't working either
     if (!$comment->save()) {
         abort(400, $comment->errors);
     }
     return $comment;
 }