public function getThreadAttribute() { if ($this->type == 'Thread') { return \Christhompsontldr\Laraboard\Models\Thread::findOrFail($this->id); } return \Christhompsontldr\Laraboard\Models\Thread::findOrFail(self::ancestors()->where('type', 'Thread')->first()->id); }
/** * */ public function show($category_slug, $slug) { $board = Board::whereSlug($slug)->firstOrFail(); // @todo figure why can't paginate on getDescendants(); $threads = Post::where('id', $board->id)->first()->getDescendants(); $threads = Thread::whereIn('id', $threads->pluck('id'))->paginate(config('laraboard.thread.limit', 15)); return view('laraboard::board.show', compact('board', 'threads')); }
public function open($slug) { $thread = Thread::whereSlug($slug)->closed()->first(); if (!$thread) { return redirect()->back()->with('error', 'This thread is already open.'); } $thread->status = 'Open'; if (!$thread->save()) { return redirect()->back()->with('error', 'There was an issue opening the thread.'); } return redirect()->back()->with('success', 'Thread opened.'); }
public function getUnreadAlertsAttribute() { $ids = $this->unreadNotifications->where('data.alert.parent_id', '!=', null)->pluck('data.alert.parent_id')->unique(); return \Christhompsontldr\Laraboard\Models\Thread::whereIn('id', $ids)->get(); }