从 Laravel 中的通知数据库中提取数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47653232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:03:07  来源:igfitidea点击:

Extracting data from notification database in Laravel

laravellaravel-5laravel-notification

提问by Ying

I was saved my notification into database like this:

我的通知被保存到数据库中,如下所示:

public function toDatabase($notifiable)
    {
        return [
            'from' => $this->message->name,
            'name'=> $this->message->email,
            'subject' => $this->message->subject,
            'body' => $this->message->body
        ];
    }

it work fine. Now i want to extract that data into my view, so i do like this:

它工作正常。现在我想将该数据提取到我的视图中,所以我这样做:

@foreach ( Auth::user()->unreadNotifications as $notification)
                <li><!-- start message -->
                    <a href="#">
                        <!-- Message title and timestamp -->
                        <h4>
                            {{ $notification->name }}
                            <small><i class="fa fa-clock-o"></i> 5 mins</small>
                        </h4>
                        <!-- The message -->
                        <p>{{ $notification->subject }}</p>
                    </a>
                </li>
            @endforeach

but it give me nothing. so am i do it wrongly?

但它什么也没给我。所以我做错了吗?

回答by Christophvh

Noted from the comments The Notification object has a data attribute where all your data is stored so to access it:

从评论中注意到 Notification 对象有一个 data 属性,您的所有数据都存储在其中以便访问它:

change:

改变:

{{ $notification->name }}

to

{{ $notification->data['name'] }}

and do this for all your data.

并对您的所有数据执行此操作。