我正在尝试获取用户的通知。但是,当我在NotificationController中启动get()方法时,它总是返回null。这是我用来调试此功能的实际代码:
function get(){
$user = \App\User::find(12);
dd($user->notifications);
}
路线是用POST方法,我用Postman来测试它。我总是得到错误500,内容为空。
你知道为什么吗?
提前谢谢你
[编辑]
这是带有POST请求的get()方法的dd($user)的结果:
{
"id": 13,
"rang": 1,
"image": "https://www.drupal.org/files/profile_default.jpg",
"firstname": "Donald",
"lastname": "Torp",
"email": "ashlynn.mcclure@pacocha.com",
"created_at": null,
"updated_at": null
}
这实际上是我的DB notifications表的内容:
ID : e7f54269-a5ff-4109-9b8a-c2328fb6cf98
Type : App\Notifications\IdeaSelected
notifiable_type : App\Idea
notifiable_id : 13
data : {"idea":{"id":39,"name":"okeefe","description":"Sunt soluta et eum. Vitae sint adipisci et excepturi eos est exercitationem velit. Mollitia hic aut aperiam cum incidunt dolorem sed. Ut blanditiis eos temporibus hic illum quis.","image":"https:\/\/lorempixel.com\/400\/280\/?98265","user":13,"created_at":null,"updated_at":null}}
read_at :
created_at : 2018-04-14 00:57:37
的结果
return (dd($user->load('notifications')));
:
#relations: array:1 [
"notifications" => DatabaseNotificationCollection {#549
#items: []
}
]
如果我将notifiable\u type从App\Idea更改为App\User,则返回结果:
[
{
"id": "e7f54269-a5ff-4109-9b8a-c2328fb6cf98",
"type": "User::class",
"notifiable_type": "App\\User",
"notifiable_id": 13,
"data": {
"idea": {
"id": 39,
"name": "okeefe",
"description": "Sunt soluta et eum. Vitae sint adipisci et excepturi eos est exercitationem velit. Mollitia hic aut aperiam cum incidunt dolorem sed. Ut blanditiis eos temporibus hic illum quis.",
"image": "https://lorempixel.com/400/280/?98265",
"user": 13,
"created_at": null,
"updated_at": null
}
},
"read_at": null,
"created_at": "2018-04-14 00:57:37",
"updated_at": "2018-04-14 00:57:37"
}
]