【发布时间】:2021-12-25 10:10:59
【问题描述】:
我有三个相关的模型:Article、ArticleBlock、ArticleBlockImage
ArticleBlock 与 Article 相关,ArticleBlockImage 与 ArticleBlock 相关
这里是关系
文章
public function article_blocks()
{
return $this->hasMany('App\Models\ArticleBlock');
}
文章块
public function article()
{
return $this->belongsTo('App\Models\Article');
}
public function article_block_images()
{
return $this->hasMany('App\Models\ArticleBlockImage');
}
ArticleBlockImage
public function article_block()
{
return $this->belongsTo('App\Models\ArticleBlock');
}
在ArticleBlockImage 模型中,我有一个函数需要以$article->id 类型的形式获取当前Article 的ID
我正在尝试做这样的事情,但我得到了错误
$article = article_block_images()->article_block()->article()->get();
"message": "调用未定义函数 App\Models\article_block_images()",
【问题讨论】:
标签: laravel relationship