gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:51:19 36 4
gpt4 key购买 nike

函数 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/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com