model
一表關聯二表
public function ordercode() { return $this->hasOne(AppModelsOrderCode::class,'id','ordercodeid'); }
二表關聯三表
public function order() { return $this->hasOne(AppModelsOrder::class,'id','orderid'); }
controller
通過一表拿三表數據
//查詢數據 $settlement = new OrderCodeSettlement(); $dataTypeContent = $settlement->with('ordercode','ordercode.order')->SettlementBusinessId($id)->paginate($pa,['*'],'page', $curt_page); //輸出 foreach ($dataTypeContent as $val) { echo $val->ordercode->order->order_no.' '; }