Exemplo n.º 1
0
 /**
  * Create a new post
  * @param string $body Content of post, will be run through filters
  * @param integer $threadid Thread ID
  * @param integer| $posterid Poster's ID. Defaults to currently authenticated user
  * @param bool|false $hidden Is the post hidden from normal view?
  * @param bool|true $save Should the post be automatically saved into the database?
  * @return Post The resulting post object
  */
 public static function newPost($body, $threadid, $posterid = null, $hidden = false, $save = true)
 {
     // Check users rights
     if (!Auth::check() && $posterid === null) {
         abort(403);
         // 403 Forbidden
     }
     // Check thread
     $thread = Thread::findOrFail($threadid);
     if ($thread->locked) {
         abort(403);
         // 403 Forbidden
     }
     // Run post through filters
     $body = PostProcessor::preProcess($body);
     // Create new post
     $post = new Post();
     $post->thread_id = $threadid;
     $post->poster_id = Auth::user()->id;
     $post->body = $body;
     $post->hidden = $hidden;
     // defaults to false
     // Put post into database
     if ($save) {
         $post->save();
     }
     return $post;
 }
Exemplo n.º 2
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $this->data['post'] = App\Post::findOrFail($id);
     $this->data['thread'] = App\Thread::findOrFail($this->data['post']->thread_id);
     if (!\Auth::hasPerm($this->data['post']->user_id)) {
         \Session::flash('flash_message', 'You do not have permission to edit this post.');
         return redirect('thread/' . $this->data['post']->thread_id);
     }
     return view('forum.posts.edit', $this->data);
 }
 public function update($id, ThreadRequest $request)
 {
     if (Auth::user()->role->name === 'admin') {
         $thread = Thread::findOrFail($id);
         $thread->update($request->all());
     } else {
         $thread = Auth::user()->threads()->findOrFail($id);
         $thread->update($request->all());
     }
     return redirect('threads');
 }
Exemplo n.º 4
0
 public function update($id)
 {
     try {
         $thread = Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
         return redirect('messages');
     }
     $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => Input::get('message')]);
     $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => Auth::user()->id]);
     $participant->last_read = new Carbon();
     $participant->save();
     return redirect('/message/' . $id);
 }
Exemplo n.º 5
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     try {
         App\Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return redirect('/');
     }
     $this->data['posts'] = App\Thread::findOrFail($id)->posts()->select('posts.*', 'threads.forum_id')->join('threads', 'threads.id', '=', 'posts.thread_id')->paginate(10);
     foreach ($this->data['posts'] as $post) {
         $post->user = App\Post::findOrFail($post->id)->author;
         $post->user->post_count = App\User::findOrFail($post->user->id)->posts()->count();
     }
     $this->data['forum'] = App\Forum::where('id', $this->data['posts'][0]->forum_id)->first();
     $this->data['thread'] = App\Thread::where('id', $id)->first();
     return view('forum.threads.show', $this->data);
 }
 public function postComment(Request $request)
 {
     $thread = Thread::findOrFail($request->input('thread_id'));
     $user = User::where('id', '=', Auth::user()->id)->first();
     $relation = Relation::where([['user_id', '=', $user->id], ['thread_id', '=', $thread->id]])->first();
     if (empty($relation)) {
         $relation = User::find(Auth::user()->id)->threads->find($thread->id);
         if (empty($relation)) {
             return Response::json(['response' => 'error']);
         }
         $comment = new Comment(['comments' => $request->input('comments')]);
         $comment->user_id = $user->id;
         $comment->relation_id = $relation->id;
         $comment->save();
         return Response::json(['response' => 'Ok', 'comment' => $comment]);
     } else {
         $comment = new Comment(['comments' => $request->input('comments')]);
         $comment->user_id = $user->id;
         $comment->thread_id = $relation->thread_id;
         $comment->save();
         return Response::json(['response' => 'Ok', 'comment' => $comment]);
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($thread_id, $comment_id)
 {
     $thread = Thread::findOrFail($thread_id);
     $comment = $thread->comments()->findOrFail($comment_id);
     return $comment;
 }
Exemplo n.º 8
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     //we recover the Thread to update
     $aThread = Thread::findOrFail($id);
     // if we want to update the content
     if ($request->has('Content')) {
         $aThread->update($request->all());
         session()->flash('flash_message', 'Thread updated');
     } else {
         // we want to publish/unpublish it
         if ($aThread->Pending == 0) {
             $aThread->Pending = 1;
             session()->flash('flash_message', 'Thread unpublished');
         } else {
             $aThread->Pending = 0;
             session()->flash('flash_message', 'Thread published');
         }
         $aThread->save();
     }
     // We go back to the list of Threads for the current Conversation
     return redirect('Thread/' . $aThread->conversation_id);
 }
Exemplo n.º 9
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $thread = Thread::findOrFail($id);
     return view('bbs.show', compact('thread'));
 }
Exemplo n.º 10
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $thread = Thread::findOrFail($id);
     $posts = DB::table('posts')->where('thread_id', $id)->get();
     return view('Forum.Thread', compact('thread', 'posts'));
 }