【发布时间】:2016-12-21 00:41:13
【问题描述】:
我正在尝试在我的主页上显示 2 个不同的列
我有一个BrowseController.php 文件:
/**
* @return mixed
*/
public function getTrending()
{
$posts = $this->posts->getTrending(null, ['category' => Input::get('category'), 'timeframe' => Input::get('timeframe')]);
return View::make('post.list')->with('title', t('Trending'))->with('posts', $posts);
}
/**
* @return mixed
*/
public function getLatest()
{
$posts = $this->posts->getLatest(null, ['category' => Input::get('category'), 'timeframe' => Input::get('timeframe')]);
$title = t('Latest');
return View::make('post.list', compact('title', 'posts'));
}
还有一个PostsRepository.php 文件:
public function getTrending($type = null, $param = [])
{
isset($param['timeframe']) ? $param['timeframe'] = $param['timeframe'] : $param['timeframe'] = 'month';
$posts = $this->posts($type, $param)->with('comments', 'votes', 'category', 'user', 'votes.user')
->leftJoin('votes', 'posts.id', '=', 'votes.post_id')
->leftJoin('comments', 'posts.id', '=', 'comments.post_id')
->select('posts.*', DB::raw('count(votes.post_id)*5 as popular'))
->groupBy('posts.id')->with('user')->orderBy('popular', 'desc');
$posts = $posts->paginate(perPage());
return $posts;
}
public function getLatest($type = null, $param = [])
{
$posts = $this->posts($type, $param)->with('comments', 'votes', 'category', 'user', 'votes.user')->orderBy('approved_at', 'desc')->paginate(perPage());
return $posts;
}
在我的刀片 php 文件中,我正在尝试使用这 2 个函数,但只有一个在工作,因为在我的 routes.php 文件中我有这个:
Route::get('/', ['as' => 'home', 'uses' => 'BrowseController@getLatest']);
所以@foreach($posts as $post) @endif 只加载getLatest 而不是getTrending
谁能帮帮我?
【问题讨论】:
标签: php laravel laravel-4 laravel-5