Laravel 5 Laravel 5.0雄辩的三级关系
我有三张桌子 属性:Laravel 5 Laravel 5.0雄辩的三级关系,laravel-5,eloquent,relationship,Laravel 5,Eloquent,Relationship,我有三张桌子 属性: public function PropertyPrice(){ return $this->hasMany('App\PropertyPrice','property_id'); } public function Currency(){ return $this->belongsTo('App\Currency','currency_id'); } public function Property(){
public function PropertyPrice(){
return $this->hasMany('App\PropertyPrice','property_id');
}
public function Currency(){
return $this->belongsTo('App\Currency','currency_id');
}
public function Property(){
return $this->belongsTo('App\Property','property_id');
}
public function PropertyPrice(){
return $this->hasMany('App\PropertyPrice','property_id');
}
public function Currency(){
return $this->belongsTo('App\Currency','currency_id');
}
public function Property(){
return $this->belongsTo('App\Property','property_id');
}
public function PropertyPrice(){
return $this->hasMany('App\PropertyPrice','property_id');
}
public function Currency(){
return $this->belongsTo('App\Currency','currency_id');
}
public function Property(){
return $this->belongsTo('App\Property','property_id');
}
物业价格模型:
public function PropertyPrice(){
return $this->hasMany('App\PropertyPrice','property_id');
}
public function Currency(){
return $this->belongsTo('App\Currency','currency_id');
}
public function Property(){
return $this->belongsTo('App\Property','property_id');
}
货币模型
public function PropertyPrice(){
return $this->hasMany('App\PropertyPrice','currency_id');
}
现在,我正在执行这一雄辩的命令,以获得具有价格的房产
Property::with('PropertyPrice')->orderBy('ordering','desc')->paginate(10);
但我不知道如何获得货币名称?请注意,我已经看到了官方文件中“Has Many Through”下提供的示例,但这是一个不同的示例,我无法与之联系
请帮忙,谢谢
$properties = Property::with('PropertyPrice')->orderBy('ordering','desc')->paginate(10);
然后
用同样的逻辑,你也可以在你看来这样做我在做一些实验,找到了答案
Property::with(['PropertyPrice' => function($query){
$query->with('Currency');
}
])->orderBy('ordering','desc')->paginate($per_page);
谢谢兄弟,我通过实验得到了答案,但你的建议也非常有益,谢谢你的时间