ミニ CMS タイプのコンポーネントを作成しようとしていますが、3 つのモデルがあります。
Page.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");
}
}
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に入っています!