【发布时间】:2018-11-05 21:24:36
【问题描述】:
我正在开发一个 Laravel-5.4 项目。我的数据库中有三个表 users、articles 和 comments。
articles 表截图:
comments 表的屏幕截图:
Article型号:
class Article extends Model
{
public function comments() {
return $this->morphMany('App\Comment', 'commentable');
}
}
Comment模特:
class Comment extends Model
{
public function commentable() {
return $this->morphTo();
}
}
ArticleController 包含以下方法:
public function showComments() {
return Article::find(1)->comments;
}
以上showComments() 方法返回[](空数组)。我想退回文章中包含id=1 的所有cmets。有什么问题?
【问题讨论】:
标签: laravel