This is my current solution, and it's really ugly
public function show($category_id, $subject_id)
{
$items = 15;
if(!Input::get('page')) {
$posts = Post::where('subject_id',$subject_id)->paginate($items);
Paginator::setCurrentPage($posts->getLastPage());
}
$subject = Subject::find($subject_id);
$posts = Post::where('subject_id',$subject_id)->paginate($items);
$category = Category::find($category_id);
return View::make('subjects.show')
->with(compact('subject'))
->with(compact('posts'))
->with(compact('category'));
}
Solution seems pretty much fine to me --- but why do you need to call the identical query twice on posts? Unnecessary. Simply place that line after $items = 15, then delete it in the two current positions, and behavior should be identical.
You need to call Paginator::setCurrentPage() before any pagination.
That's why He does it like this I guess.
Why not just sort in the different direction, so the last entry is displayed on the first page?
Post::where('subject_id',$subject_id)->orderBy('created_at','desc')->paginate(10);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community