我要在Laravel創建博客。現在我在博客中發佈表單分類,並且我只能根據帖子顯示分頁,但是我想僅針對與分類標識具有關聯性的帖子顯示分頁。根據laravel關係表中的數據顯示paginate
我的代碼中存在一些問題,請幫助我解決我的問題。
在控制器源代碼:
//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()}}
但我不能表現出與職位PAGINATE有關係,與分類號
你想分頁有哪些類別的所有職位?因爲現在你正在對類別進行分頁,而不是帖子。 –
這個代碼只是分類的分類,但我想顯示分頁根據職位有關係與類別 – alireza