저는 소셜 앱 프런트 엔드 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가 게시는 고함 소리, 기사 또는 이야기 wheather를 유형 의미 야유, 기사 및 이야기에 _ID에 속하는 : 나는 모델과 같은 것이있다.
는 나는이 내가 단지 만 야유 즉 하나 개의 모델에서 post_id를 해당 데이터와 함께 데이터를 게시 얻을 수있는 사용
Publish::with('getdata')->where('user_id',Auth::user()->id)->get();
을 사용하고이
//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');
}
}
같은 모델이있다. 나는이 세 표 모두에서 이것을 원한다.
모델 데이터를 해당 post_id 데이터와 함께 가져오고 싶습니다. 어떻게하면 능변을 사용하여 단일 쿼리를 수행 할 수 있습니까?
정말 열심히 당신이 무엇을 요구하고 있습니다. \ –
@Gaz_Edge 코드를 업데이트했습니다. 친절하게 검토 .how 내가 외래 키 publish_id를 갖는 세 가지 모델에서 post_id 해당 데이터와 함께 모델 데이터를 게시 할 수 있습니까? –