请问下这种查询如何写
查询代码
Order::with("log")->first();
Order模型中 log方法
public function log()
{
return $this->
hasMany(Log::class,'order_id',')
}
疑问:我的log表中有userId字段,想通过一个自定义方法通过log表中的userId查询userinfo带到log中一起返回到上面的Order信息查询条件中,我该如何写log方法
按照你的描述, 逻辑关系应该是
order (一)-> log(多) -> user(一), 属于典型的
一对多
&多对一
先定义
Order
与Log
的关系模型在定义
Log
与User
的关系模型使用