我正在尝试制作一个迷你 CMS 类型的组件,我有三个模型:
页面.php
class Page extends Eloquent {
protected $table = 'pages';
public function content() {
return $this->hasManyThrough('Content', 'PageGroup');
}
public function groups() {
return $this->hasMany('PageGroup');
}
}
PageGroup.php
class PageGroup extends Eloquent {
protected $table = 'page_groups'
public function group() {
return $this->hasMany("Content");
}
}
内容.php
class Content extends Eloquent {
protected $table = 'content';
public function content() {
return $this->hasMany("Content");
}
}
编辑:我已经用正确的关系建立了我的关系模型。
$page = Page::find(1);
$page_group = $page->groups()->where('id', '=', 1)->get();
返回PageGroup
属于 的集合Page
。我想我的新问题是是否有可能从该收藏中获得收藏......比如:
$content = $page_group->content;
因为那会返回:
Undefined property: Illuminate\Database\Eloquent\Collection::$content
这有道理吗?我为新手问题道歉;我刚刚进入 Laravel!