gpt4 book ai didi

php - 如何限制 Laravel 中的通知数量

转载 作者:行者123 更新时间:2023-12-02 06:13:52 29 4
gpt4 key购买 nike

我试过 ->limit(4)方法,但这似乎不起作用

@foreach(auth()->user()->unreadNotifications()->limit(4) as $notification)
<li>
<a href="profile.html">
<div>
{{ $notification->data['message'] }}<span class="pull-right text-muted small">{{ time_elapsed_string($notification->created_at) }}</span>
</div>
</a>
</li>
@endforeach

最佳答案

您不要在此处执行查询:

@foreach(auth()->user()->unreadNotifications()->take(4)->get() as $notification)

还有,你 shouldn't run queries in Blade files .

关于php - 如何限制 Laravel 中的通知数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47946225/

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