正在将 Laravel 通知从数据库检索到 blade
Retrieving Laravel notification from database to blade
所以我想从 laravel 中的通知 Table 中检索数据。
但我想做的是在 public 上显示通知,这意味着没有授权所以它会显示在这里
notification example
如果我这样做它会抛出一个错误作为未定义的变量
@foreach( $notifications as $notif)
lob {{ $notif->type }}
@endforeach
然后我尝试计算未读通知数,但它抛出了
的错误
Trying to get property 'unreadNotifications' of non-object
我应该在这里做什么?因为在我搜索了这个之后,
该解决方案始终使用 auth()->user()->notifications()
同时我正在尝试做的是在 home.blade.php 中显示通知而无需任何授权
此致。
由于没有任何登录用户而失败。
auth()->user()
如果有登录用户则抓取,否则 returns null.
你在这里要做的是获取你想要通知的用户,然后调用它的通知关系。例如:对于用户 id 1 的抓取通知,它将是 \App\User::find(1)->notifications
所以我想从 laravel 中的通知 Table 中检索数据。
但我想做的是在 public 上显示通知,这意味着没有授权所以它会显示在这里
notification example
如果我这样做它会抛出一个错误作为未定义的变量
@foreach( $notifications as $notif)
lob {{ $notif->type }}
@endforeach
然后我尝试计算未读通知数,但它抛出了
的错误Trying to get property 'unreadNotifications' of non-object
我应该在这里做什么?因为在我搜索了这个之后,
该解决方案始终使用 auth()->user()->notifications()
同时我正在尝试做的是在 home.blade.php 中显示通知而无需任何授权
此致。
由于没有任何登录用户而失败。
auth()->user()
如果有登录用户则抓取,否则 returns null.
你在这里要做的是获取你想要通知的用户,然后调用它的通知关系。例如:对于用户 id 1 的抓取通知,它将是 \App\User::find(1)->notifications