public function postReply() { try { $board_id = Arr::get($_POST, 'board_id', null); $labels = Arr::get($_POST, 'labels', array()); $content = Arr::get($_POST, 'content', ''); if ($board_id === null || empty($content)) { throw new Exception('回覆失敗'); } $br = new BoardReply(); $br->tags = serialize($labels); $br->content = $content; $br->creator = Sentry::getUser()->getId(); $br->created_at = date('Y-m-d H:i:s'); $br->board_id = $board_id; $br->save(); //update status of board $b = Board::find($board_id); $b->isReply = '1'; $b->save(); return Redirect::route('admin.board.list'); } catch (Exception $e) { return Redirect::back()->withInput()->withErrors($e->getMessage()); } }
public function getPost($postId) { // board $b = \Board::find($postId); if ($b === NULL) { return \Redirect::route('frontend.board.list'); } $b->count_num = $b->count_num + 1; $b->save(); $b->d = str_replace('-', '/', substr($b->created_at, 0, 10)); $isShowPost = false; if ($b->isPrivate == '0') { $isShowPost = true; } else { $user_id = \Auth::check() ? \Auth::user()->id : null; $isShowPost = $user_id === $b->user_id && $user_id !== null; } // fetch reply $br = \BoardReply::where('board_id', '=', $postId)->orderBy('created_at', 'desc')->first(array('tags', 'content', \DB::raw("date_format(created_at,'%Y/%m/%d') as d"))); $tags = array(); if ($br !== null) { $tagsId = unserialize($br->tags); $tags = \ServiceFaq::find($tagsId, array('id', 'title')); } // get next and previous $sql = 'select * from ' . '(select id, topic, created_at from board where created_at < ? and status = "1" order by created_at desc limit 0, 1) as T ' . 'union select * from ' . '(select id, topic, created_at from board where created_at > ? and status = "1" order by created_at asc limit 0, 1) as T order by id asc'; $rows = \DB::select($sql, array($b->created_at, $b->created_at)); $list = array('next' => null, 'prev' => null); foreach ($rows as &$r) { if ($r->created_at > $b->created_at) { $list['next'] = $r; } if ($r->created_at < $b->created_at) { $list['prev'] = $r; } } return \View::make('aesthetics.board.view_post', array('board' => &$b, 'list' => &$list, 'reply' => &$br, 'tags' => &$tags, 'isShowPost' => $isShowPost)); }