【发布时间】:2016-03-02 12:59:56
【问题描述】:
我的下一个问题是订购具有 hasMany 关系且订购字段在关系中的项目。
我有表:国家,它只有 ID 字段 我还有表:country_translation,其中有列:名称、语言
在我的 CountryController 中的 index() 方法中,我想显示默认语言的所有国家/地区,按参数名称对它们进行排序并对其进行分页。
这是我的国家模型:
class Country extends Model {
protected $fillable = [
'code', 'latitude', 'longitude', 'currency_id', 'timezone', 'dam_date', 'status',
];
public function translations() {
return $this->hasMany('App\Models\CountryTranslation');
}
}
国家翻译模型:
class CountryTranslation extends Model {
protected $fillable = [
'name', 'lang', 'country_id',
];
public function country() {
return $this->hasOne('Country');
}
}
【问题讨论】:
标签: php laravel relationship