public function productFaq() {
return $this->hasMany('App\Models\ProductFaq', 'product_id');
}
public function answers(){
return $this->hasMany('App\Models\ProductFaqAnswers','faq_id');
}
'productFaq' => function($faq){
$faq->selectRaw('faq_id,user_id,user_name,product_id,product_name, date_of_enquiry,published,question')
->with(['answers' => function($answers)
{
$answers->select(['faq_id','answer','user_name','date_of_answer'])
->where('published','=',1);
}
]);
},
答案 0 :(得分:1)
您只能在模型上调用with
方法,而不能在querybuilder上调用方法,因此它应该是第一条语句,因为当您可以selectRaw
时,它将返回一个新的querybuilder实例: / p>
$faq->with(['answers' => function($answers) {
$answers
->select(['faq_id','answer','user_name','date_of_answer'])
->where('published','=',1);
}])
->selectRaw('faq_id,user_id,user_name,product_id,product_name,
date_of_enquiry,published,question')->get();