我的模型是Patient -> Sample
,我删除了一个病人,我通过withTrashed()
查询被删除的病人,但是不通过withTrashed();
查询被删除病人的样本
Patient_Controller
class Patient_Controller extends Controller{
public function query(Request $request){
$result = Patient_Model::withTrashed();
->orderBy("updated_at","desc")
->Paginate(15)
->toJson();
return $result;
}
但是在Sample_Controller
class Sample_Controller extends Controller{
public function query(Request $request){
$result = Sample_Model::with('patient')
->withTrashed()
->orderBy("updated_at","desc")
->Paginate(15)
->toJson();
return $result;
}
但是with not find delete Patient,所以我的样本不能得到病人信息
如果我对你的问题理解正确的话,你是想把垃圾病人包括在你的名单里吗?如果是,则尝试以下操作:
public function query(Request $request){
$result = Sample_Model::with(['patient' => function($q) {
$q->withTrashed();
}])
->withTrashed()
->orderBy("updated_at","desc")
->Paginate(15)
->toJson();
return $result;
}