【发布时间】:2020-07-26 04:31:46
【问题描述】:
我是使用 laravel 的新手。当我尝试使用 laravel 通知在网站上显示数据时,我遇到了一个问题。 这是我的代码:
GameBiddedNotification.php:
public function toDatabase($notifiable)
{
return[
'title' => $this->details['title'],
'text' => $this->details['text']
];
}
这是数据库模板,在数据列中:
{"title":"hg","text":"\u10db\u10dd\u10d7\u10d0\u10db\u10d0\u10e8\u10d4 \u10e8\u10d4\u10db\u10dd\u10d5\u10d8\u10d3\u10d0"}
这是我的刀片:
@foreach(auth()->user()->unreadNotifications as $notification)
@php
$data = json_decode($notification,true);
$test = $data['title'] ['text'];
@endphp
<a class="dropdown-item preview-item">
<div class="preview-thumbnail">
<div class="preview-icon bg-dark rounded-circle">
<i class="mdi mdi-xbox-controller text-success"></i>
</div>
</div>
<div class="preview-item-content">
{{-- <p class="preview-subject mb-1">{{ $notification->data['title'] }}</p> --}}
<p class="text-muted ellipsis mb-0">{{ $test }}</p>
</div>
</a>
@endforeach
我尝试了多种方法,例如:
{{ $notification->data['title'] }}
,但结果是一样的。我总是收到一个错误提示
ErrorException (E_ERROR)
Undefined index: title
【问题讨论】:
标签: php laravel laravel-blade