简体   繁体   English

获取laravel中一个分页器所有页面的项

[英]Get items of all the pages of a paginator in laravel

Hello I hope you help me because I am in a real pinch rn, Deadline after 2 days and I am stuck with a part were I have some paginated data displayed and I want that data to be sorted when I press on a button in Laravel-9 but the thing is that I can't find any ways to retrieve all the items of the paginator (I only get the items of the first page).你好,我希望你能帮助我,因为我真的很紧张,2天后的最后期限,如果我显示了一些分页数据,我希望在按下 Laravel 中的按钮时对这些数据进行排序- 9 但问题是我找不到任何方法来检索分页器的所有项目(我只得到第一页的项目)。

What I did: I made a form that have a button that submits the form and triggers the sorting method in that form I added a hidden input that has as value the paginator instance in my blade view.我做了什么:我制作了一个表单,该表单有一个按钮,用于提交表单并触发该表单中的排序方法我添加了一个隐藏的输入,该输入在我的刀片视图中具有分页器实例的值。 This paginator instance has two pages each one have 2 items这个分页器实例有两个页面,每个页面有 2 个项目

$events = Event::where('endingAt', '>', Carbon::now('GMT+1'))->paginate(2);

To see it clearly here's a dd of that $events variable为了清楚地看到它,这里是$events变量的dd

^ array:2 [▼
  0 => {#294 ▼
    +"id": 18
    +"title": "Gaming Hackathon"
    +"object": "This hackathon is a competition between different selected teams with an objective of building a full functional game in 3 days!!"
    +"startingAt": "2022-08-12 06:30:00"
    +"endingAt": "2022-08-14 21:00:00"
    +"location": "Kabukichō Ichiban-gai, Shinjuku, Tokyo, Japan"
    +"room": "III-5"
    +"created_at": "2022-08-11T11:07:47.000000Z"
    +"updated_at": "2022-08-11T11:07:47.000000Z"
  }
  1 => {#293 ▼
    +"id": 19
    +"title": "Soft Skills Course"
    +"object": "This event is a course available for our employees to further develop their soft skills and especially negotiation and communication skills"
    +"startingAt": "2022-08-12 09:00:00"
    +"endingAt": "2022-09-12 18:40:00"
    +"location": "11, Amdl Rabat, Rue Al Kayraouane , Hassan, Rabat, Morocco"
    +"room": "Open Space"
    +"created_at": "2022-08-11T11:10:30.000000Z"
    +"updated_at": "2022-08-11T11:10:30.000000Z"
  }
]

it only returns 2 items out of 4 which means that it only returns the paginator's first page's items.它只返回 4 个项目中的 2 个,这意味着它只返回分页器的第一页项目。 how can i make sure that i get the items of all the paginator's pages?如何确保获得所有分页器页面的项目? And thank you for the time you spent reading this:D感谢您花时间阅读本文:D

if you want all the items you don't want to paginate so just call get instaed of paginate如果您想要所有不想分页的项目,那么只需调用 get instaed of paginate

$events = Event::where('endingAt', '>', Carbon::now('GMT+1'))->get();

Thanks for anyone who viewed, and especially @BobB for actually making an effort to Help.感谢所有观看过的人,尤其是@BobB,感谢他们真正努力提供帮助。 I've solved it by pushing query results to the session before paginating them, I know it would hinder the website's performance but Its just a temporary fix, I guess I will create a temp table in the database and store/remove that data in it whenever I need.我已经通过在对它们进行分页之前将查询结果推送到 session 来解决它,我知道这会阻碍网站的性能,但这只是一个临时修复,我想我会在数据库中创建一个临时表并在其中存储/删除该数据每当我需要。 That's the best solution Ii thought of, if you got a better solution please lemme know:D这是我想到的最好的解决方案,如果您有更好的解决方案,请告诉我:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM