2016-09-18 70 views
0

的功能simplePaginate()直接调用where()功能类似,经过工作:Laravel 5 - SimplePaginate函数在这里不起作用?

$posts = $userA->Posts()->simplePaginate(10)->get(); 

的帖子()函数在用户雄辩:

public function Posts(){ 
    return Post::where('user_id','$this->id')->where('category','programming'); 
} 

对于尚未一切工作正常,但问题是当我有一个以上的用户,所以我做了这个:

//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); 

laravel Documentation我没有找到simplePaginate() 功能,但它的工作where()功能后,所以,请 帮助

回答

0

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