Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting data from notification database in Laravel

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?

like image 594
Ying Avatar asked Dec 05 '17 12:12

Ying


1 Answers

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

change:

{{ $notification->name }}

to

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

and do this for all your data.

like image 88
Christophvh Avatar answered Sep 27 '22 20:09

Christophvh