Kha*_* Bz 1 php collections function laravel-5
在直接simplePaginate()调用where()函数后,函数正在工作:
$posts = $userA->Posts()->simplePaginate(10)->get();
Run Code Online (Sandbox Code Playgroud)
User Eloquent 中的 Posts() 函数:
public function Posts(){
return Post::where('user_id','$this->id')->where('category','programming');
}
Run Code Online (Sandbox Code Playgroud)
然而一切正常,但问题是当我拥有多个用户时,所以我做了这个:
//Creating Empty Collection (Working Without any problem)
$posts = new \Illuminate\Database\Eloquent\Collection;
//Getting and Adding the userA Posts (Working Without any problem)
$userA_Posts = $userA->Posts();
$posts = $posts->merge($userA_Posts);
//Getting and Adding the userB Posts (Working Without any problem)
$userB_Posts = $userB->Posts();
$posts = $posts->merge($userB_Posts);
//Getting and Adding the userC Posts (Working Without any problem)
$userC_Posts = $userC->Posts();
$posts = $posts->merge($userC_Posts);
//Here Laravel Shows me an ERROR {Method simplePaginate does not exist}
$posts = $posts->sortByDesc('created_at')->simplePaginate(10)->values()->all();
//I changed it to this, ERROR {Method simplePaginate does not exist}
$posts = $posts->sortByDesc('created_at')->values()->simplePaginate(10)->all();
//I changed it to this, ERROR {Method simplePaginate does not exist}
$posts = $posts->sortByDesc('created_at')->values()->all()->simplePaginate(10);
Run Code Online (Sandbox Code Playgroud)
在laravel 文档中我没有找到
simplePaginate()Function 但它在where()Function之后工作,所以请帮助
| 归档时间: |
|
| 查看次数: |
2768 次 |
| 最近记录: |