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

标签 php function collections laravel-5

函数 simplePaginate() 在直接调用 where() 函数后开始工作:

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

User Eloquent 中的 Posts() 函数:

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

In the laravel Documentation I didn't find the simplePaginate() Function But it's working after the where() Function , So please Help

最佳答案

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

关于php - Laravel 5 - SimplePaginate 函数在这里不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39555052/

相关文章:

collections - 将一个元素放在集合的尾部

java - 如何索引 java.util.Collections$UnmodifyingMap 的类类型?

java - 对列表进行分类的最佳方法

PHP 脚本加载大约需要 15 秒

php - 在 Joomla 中处理 E_STRICT

c++ - C++ 中对 const Callable 的引用和对 Callable 的引用之间的区别

C++,传递给函数的fstream对象作为引用,const?

PHP session 看起来已损坏

php - 通过函数传递 PHP 变量

actionscript-3 - as3函数指针