我与模型具有以下关系
class order
{
public function finances()
{
return $this->belongsTo(Finance::class,'finance_id');
}
}
class Finance
{
public function prices()
{
return $this->hasMany(Price::class, 'finance_id');
}
public function latestPrice()
{
return $this->hasOne(Price::class,'finance_id')->latest();
}
public function orders()
{
return $this->hasMany(Order::class, 'finance_id');
}
}
我执行此查询时
$orders = Order::with(['finances.prices.latestPrice'])->get();
我收到此错误。调用模型[App \ Price]上未定义的关系[latestPrice]。
答案 0 :(得分:3)
您必须遵守laravel的语法,请检查documentation:
$orders = Order::with(['finances.prices', 'finances.latestPrice'])->get();