【发布时间】:2017-05-01 08:48:18
【问题描述】:
我将在 Laravel 中创建博客。现在我在博客中获得了帖子表单类别,我只能根据帖子显示分页,但我只想为与类别 id 有关系的帖子显示分页
我的代码有问题,请帮我解决问题。
在控制器源代码中:
//this code show posts according to category id
$postCatId = $request->postCatId;
$postList =PostCat::with("posts")->where('id',$postCatId)->get();
//this code show paginate according to posts has relation with category
$paginate=PostCat::with("posts")->where('id',$postCatId)->paginate(2);
然后返回 $postList 和 $paginate 以查看
在视图中:
//show posts has relation with category id
@foreach($PostList as $post)
@foreach($post->posts as $post_item)
{{$post_item->id}}
@endforeach
@endforeach
//show paginate according to posts has relation with category id
{{$paginate->links()}}
但我无法显示与类别 ID 相关的帖子的分页
【问题讨论】:
-
您想对所有有分类的帖子进行分页?因为现在您正在对类别进行分页,而不是帖子。
-
没错,这段代码只为类别分页,但我想根据帖子显示分页与类别有关系
标签: php mysql laravel laravel-5 pagination