下面的代码显示了 laravel 中登录用户的所有未读通知:
auth()->user()->unreadNotifications
我将代码放入一个标签并将其绑定(bind)为 unreads 属性,以便我的 vue 组件可以访问 unreads
数据。
<notification :userid="{{ auth()->user()->id }}" :unreads="{{ auth()->user()->unreadNotifications }}"></notification>
一切正常。
从 vue js,我可以将未读数据限制为我想要的结果数。
但是,当我在浏览器中查看源代码时,我可以看到显示了所有通知,因此页面加载延迟,因为上面有很多结果。
现在,我想LIMIT auth()->user()->unreadNotifications
以便我可以控制要显示的结果数。我检查了谷歌和 laravel 文档,但我没有找到。有人知道吗?
最佳答案
Laravel Framework GitHub 上有一个问题建议您可以使用:
auth()->user()->unreadNotifications()->take(10)->get()
关于php - 如何限制 Laravel 中的未读通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46230104/