Я работаю над проектом Laravel-5.4. В моей базе данных три таблицы users
, articles
и comments
.
Снимок экрана articles
таблицы:
![articles table](https://i.stack.imgur.com/1cX4I.jpg)
Снимок экрана comments
таблицы:
![comments table](https://i.stack.imgur.com/dKaCz.png)
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
. В чем проблема?