Esempio n. 1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     try {
         App\Forum::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return redirect('/');
     }
     $this->data['threads'] = App\Thread::where('threads.forum_id', '=', $id)->join('users', 'users.id', '=', 'threads.user_id')->select('users.username', 'threads.*')->orderBy('threads.updated_at', 'desc')->paginate(15);
     foreach ($this->data['threads'] as $thread) {
         $thread->latest = App\Post::where('posts.thread_id', '=', $thread->id)->orderBy('posts.id', 'desc')->join('users', 'users.id', '=', 'posts.user_id')->first();
         foreach ($this->data['threads'] as $thread) {
             $thread->post_count = App\Post::where('posts.thread_id', '=', $thread->id)->count();
         }
     }
     $this->data['forum'] = App\Forum::findOrFail($id);
     return view('forum.show', $this->data);
 }
Esempio n. 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(CreateThreadRequest $request)
 {
     try {
         App\Forum::findOrFail($request->forum_id);
     } catch (ModelNotFoundException $e) {
         \Session::flash('flash_message', 'Forum does not exist');
         return redirect('/');
     }
     // replace non letter or digits with '-'
     $text = preg_replace('~[^\\pL\\d]+~u', '-', $request->title);
     // trim
     $text = trim($text, '-');
     // transliterate
     $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
     // lowercase
     $text = strtolower($text);
     // remove unwanted characters
     $text = preg_replace('~[^-\\w]+~', '', $text);
     $user_id = \Auth::user()->id;
     $thread = App\Thread::create(['forum_id' => $request->forum_id, 'user_id' => $user_id, 'title' => $request->title, 'slug' => $text]);
     App\Post::create(['user_id' => \Auth::user()->id, 'thread_id' => $thread->id, 'post' => $request->post]);
     return redirect('thread/' . $thread->id);
 }
 /**
  * Create thread page
  * @param integer $forumid Forum ID
  * @return \Illuminate\View\View
  */
 public function createThread($forumid)
 {
     $forum = Forum::findOrFail($forumid);
     return view('clearboard.pages.newthread', ['forum' => Forum::find($forumid)]);
 }