问题描述
我正在尝试计算在 laravel 中有多少未读通知没有登录用户的名称值。
auth()->user()->unreadNotifications->count()
我想出了这样的东西,但它不起作用,我不知道如何不等于而不是等于:
$numberofnotifications = auth()->user()->unreadNotifications::where('name',Auth::user()->name)->count();
解决方法
我不会测试它,但如果您查看 vendor/laravel/framework/src/Illuminate/Notifications/DatabaseNotification.php
,您会注意到一个名为 newCollection
的方法。因此,这应该符合您的要求是合理的:
$numberofnotifications = auth()->user()->unreadNotifications::newCollection()->where('name','<>',Auth::user()->name)->count();