【发布时间】:2021-04-12 00:17:22
【问题描述】:
我必须将 json 转换为来自 laravel 通知表 data 字段的 arry,
这是dd($user->notifications);上显示的数据
我需要在[] 中显示有效载荷,如下所示
{
"payload": [ {
"title": "PHP Developer Accepted",
"description": "<p>This is a professional IT Job </p>",
"user_id": 54,
"job_id": "01"
}],
"message": "",
"result": true
}
这是我的控制器索引函数
protected function index()
{
$user = DeviceAuthenticator::getUserByAccessToken();
foreach ($user->notifications as $notification) {
$notifications = $notification->data;
}
return response()->apiSuccess($notifications);
}
但在我在响应之前转储 $notifications 之前,它显示为一个数组
dd($notifications);
【问题讨论】:
标签: php arrays json laravel jsondecoder