我有一个雄辩的要求,要拿起我的类别和相关问题。
我希望该questions部分有一个分页。
public function index()
{
$data = Category::where([
['slug', '=', 'interview-questions'],
['lang', '=', auth()->user()->lang],
['profile_id', '=', auth()->user()->profile_id]
])->with(
[
'questions' => function ($query) {
$query->whereNull('parent_id')->with(
[
'answer' => function ($query) {
$query->where('user_id', auth()->user()->id);
},
]
)->orderBy('position', 'ASC')->paginate(15);
}
]
)->first();
}
这是我得到的:
data: {id: 31, title: "Interview - Questions", slug: "interview-questions", part: "interview-questions",…}
created_at: "2019-08-22 16:28:33"
deleted_at: null
id: 31
lang: "fr"
part: "interview-questions"
profile_id: 1
questions: [{id: 956, question: "<h3>1. Qu’est-ce qui vous a intéressé dans notre annonce ? </h3>",…},…]
0: {id: 956, question: "<h3>1. Qu’est-ce qui vous a intéressé dans notre annonce ? </h3>",…}
1: {id: 957,…}
2: {id: 958,…}
3: {id: 959, question: "<h3>4. Depuis combien de temps cherchez-vous du travail ?</h3>",…}
4: {id: 960,…}
5: {id: 961,…}
6: {id: 962,…}
7: {id: 963,…}
8: {id: 964, question: "<h3>9. Pourquoi avez-vous postulé chez nous (candidature spontanée) ?</h3>",…}
9: {id: 965,…}
10: {id: 966, question: "<h3>11. Racontez-moi vos expériences professionnelles.</h3>", type: "wysiwyg",…}
我的问题仅限于 10.. 只是,我没有像 Laravel 这样的分页信息应该提供它们,例如first_page_url, per_page, total, next_page_url, 等等...
为什么 ?以及如何解决这个问题?
Smart猫小萌
慕慕森
HUH函数