<?php
 namespace App\Http\Controllers\Main; use App\Http\Controllers\BaseController; use App\Util\TopicUtil; use Illuminate\Support\Facades\Input; use TechOnline\Laravel\Dao\ModelUtil; use TechOnline\Laravel\Http\Request; use TechOnline\Laravel\Http\Response; class TopicsController extends BaseController { public function index() { $pageSize = 10; $option = []; $option['order'] = ['noteCount', 'desc']; if (Request::isPost()) { $page = intval(Input::get('page', 1)); $paginateData = TopicUtil::paginateTopics($page, $pageSize, $option); TopicUtil::mergeIsFollowed($paginateData['records'], $this->memberUserId()); $html = $this->_viewRender('fragment.topicListItems', [ 'topics' => $paginateData['records'], ]); return Response::send(0, null, [ 'html' => $html, 'page' => $page, 'pageSize' => $pageSize, 'total' => $paginateData['total'], ]); } $page = 1; $paginateData = TopicUtil::paginateTopics($page, $pageSize, $option); TopicUtil::mergeIsFollowed($paginateData['records'], $this->memberUserId()); $latestTopics = ModelUtil::model('topic')->orderBy('id', 'desc')->limit(10)->get()->toArray(); return $this->_view('topics.index', [ 'page' => $page, 'pageSize' => $pageSize, 'total' => $paginateData['total'], 'topics' => $paginateData['records'], 'latestTopics' => $latestTopics, ]); } public function latest() { $pageSize = 10; $option = []; $option['order'] = ['id', 'desc']; if (Request::isPost()) { $page = intval(Input::get('page', 1)); $paginateData = TopicUtil::paginateTopics($page, $pageSize, $option); TopicUtil::mergeIsFollowed($paginateData['records'], $this->memberUserId()); $html = $this->_viewRender('fragment.topicListItems', [ 'topics' => $paginateData['records'], ]); return Response::send(0, null, [ 'html' => $html, 'page' => $page, 'pageSize' => $pageSize, 'total' => $paginateData['total'], ]); } $page = 1; $paginateData = TopicUtil::paginateTopics($page, $pageSize, $option); TopicUtil::mergeIsFollowed($paginateData['records'], $this->memberUserId()); $hotTopics = ModelUtil::model('topic')->orderBy('followerCount', 'desc')->limit(10)->get()->toArray(); return $this->_view('topics.latest', [ 'page' => $page, 'pageSize' => $pageSize, 'total' => $paginateData['total'], 'topics' => $paginateData['records'], 'hotTopics' => $hotTopics, ]); } }