Laravel 5 - SimplePaginate 函数在这里不起作用?

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之后工作,所以请帮助

小智 5

你必须删除->get(),只留下->simplePaginate(10);