model

一表關聯二表

public function ordercode()
{
return $this->hasOne(\App\Models\OrderCode::class,'id','ordercodeid');
}

二表關聯三表

public function order()
{
return $this->hasOne(\App\Models\Order::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.'\n';
}
05-11 21:44