我正在社交應用程序前端Angualar,後端laravel和數據庫Mongodb。我有類似的模型:使用關係在單一的Eloquent Query laravel中獲取數據?
Hoots
-----------------
- _id
- content
- publish_id
Article
-----------------
- _id
- content
- publish_id
Story
-----------------
- _id
- content
- publish_id
Publish
-----------------
- _id
- post_id
- type
- user_id
帖子的ID在發佈所屬hoots,文章和故事,其中type表示wheather是叱,文章或故事_id。
我有型號這樣
//Article model
class Article extends Eloquent {
public function getpublish(){
return $this->hasMany('Publish','post_id');
}
}
//Story model
class Story extends Eloquent {
public function get_publish(){
return $this->hasMany('Publish','post_id');
}
}
//Hoots model
class Hoots extends Eloquent {
public function get_publ(){
return $this->hasMany('Publish','post_id');
}
}
//Publish model
class Publish extends Eloquent {
public function getdata(){
return $this->BelongsTo('Hoots','Article','Story','publish_id');
}
}
我使用這個我只能得到與一個模型只即hoots POST_ID相應的數據一起發佈的數據使用
Publish::with('getdata')->where('user_id',Auth::user()->id)->get();
。我想從這三個表中得到這個。
我想獲取發佈模型數據及其相應的post_id數據。我如何使用口才能完成這個o單個查詢。
確實很難找出你所要求的。你能否提供你期望的結果表格?\ –
@Gaz_Edge我已經更新了代碼。 Kindly Review.how我可以獲得發佈模型數據以及具有外鍵publish_id的三個不同模型的post_id相應數據嗎? –