/** * 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()); }
/** * 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]); }
/** * 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'); } }
/** * 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')); }
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'); }
/** * 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(); }
/** * 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]); }