9

我像这样将通知保存到数据库中:

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

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

@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

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

4

1 回答 1

16

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

改变:

{{ $notification->name }}

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

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

于 2017-12-05T12:35:09.150 回答