laravel 查询不 return 关系行的全部计数
laravel query does not return the entire count of the rows of the relationship
我有一个查询,我想 return 一个对象与其关系,它有多对一的关系,一个订单可以有不止一种药物我写了这样的查询
$orders = DrugRequest::where('user_id', $user_id)->with(['drugs'])->latest()->get();
这得到关系但不是完整的行,例如,如果一个订单有两种药物,它只是 return 第一种药物,而不是两种,
这是我的关系
public function drugs(){ return $this->hasMany('App\OrderDrug' , 'order_id' , 'id');}
这是我 dd($orders)
对于索引为 11 的订单对象,我有两种药物,但它只有 return一种药物
我发现问题出在查询上,我进行了更改,结果如下:
$orders = DrugRequest::where('user_id', $user_id)->with('drugs')->latest()->get();
我有一个查询,我想 return 一个对象与其关系,它有多对一的关系,一个订单可以有不止一种药物我写了这样的查询
$orders = DrugRequest::where('user_id', $user_id)->with(['drugs'])->latest()->get();
这得到关系但不是完整的行,例如,如果一个订单有两种药物,它只是 return 第一种药物,而不是两种,
这是我的关系
public function drugs(){ return $this->hasMany('App\OrderDrug' , 'order_id' , 'id');}
这是我 dd($orders)
对于索引为 11 的订单对象,我有两种药物,但它只有 return一种药物
我发现问题出在查询上,我进行了更改,结果如下:
$orders = DrugRequest::where('user_id', $user_id)->with('drugs')->latest()->get();