【发布时间】:2017-06-17 04:10:17
【问题描述】:
我正在使用 REST API 来接收数据。
数据模型与多态相关,类似于文档中的模型:
https://laravel.com/docs/5.4/eloquent-relationships#polymorphic-relations
posts
id - integer
title - string
body - text
videos
id - integer
title - string
url - string
comments
id - integer
body - text
commentable_id - integer
commentable_type - string
假设,例如,API 正在接收这条新评论:
{
"body": "This a test comment",
"commentable_type": "posts",
"commentable_id": "1"
}
如何验证收到的 commentable_type 是否存在且有效?
【问题讨论】: