예제 #1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $topics = Topic::with('user')->orderBy('created_at', 'desc')->paginate(10);
     $data = $topics->map(function ($item, $key) {
         $item->postsCount;
         return $item;
     });
     return response()->json(['topics' => $data])->header('X-Page-Total', ceil($topics->total() / 10))->header('X-Page', $topics->currentPage());
 }
예제 #2
0
 /**
  * Show the topic
  *
  * @param  Request  $request
  * @return Response
  */
 public function show(Request $request, $id)
 {
     $topic = App\Topic::with('comment', 'comment.user')->where('id', $id)->first();
     if (empty($topic) || $topic->status == -1) {
         if (Auth::guest() || !Auth::user()->is_admin()) {
             return view('errors.topic404');
         }
     }
     return view('topic.show', ['topic' => $topic]);
 }
예제 #3
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     if (Auth::check()) {
         $actu = Actualite::orderBy('id', 'desc')->first();
         $topics = Topic::with('posts')->orderBy('created_at', 'desc')->take(5)->get();
         //$postPerTopic =
         $userLevel = $this::checkLevel();
         return view('index', ['topics' => $topics, 'actu' => $actu, 'level' => $userLevel]);
     } else {
         return view('index');
     }
 }
예제 #4
0
 /**
  * List all of the topics from a given board
  *
  * @return \Illuminate\Request
  */
 public function index()
 {
     $topics = Topic::with('topic_id', 'user_id');
     return view('topics.index', compact('topics'));
 }
예제 #5
0
 public function delete_topic($id)
 {
     $topic = Topic::with('comments')->find($id);
     if (Auth::user()->id == $topic->user_id) {
         $topic->active = 0;
         $topic->save();
         foreach ($topic->comments as $comment) {
             $comment->active = 0;
             $comment->save();
         }
     }
     return redirect('home');
 }
예제 #6
0
 /**
  * Get all of the topics for a given subject.
  *
  * @param  Subject  $subject
  * @return Collection
  */
 public function forSubject($subject_id)
 {
     return Topic::with('knowledgeunits')->where('topics.subject_id', $subject_id)->orderBy('created_at', 'asc')->get();
 }
예제 #7
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //$topics = Topic::paginate($this->nbrPerPage);
     $topics = Topic::with('user', 'posts')->orderBy('created_at', 'desc')->get();
     return view('forum.index', ['topics' => $topics]);
 }