我的问题:
在拉威尔诺瓦,如何根据国家ID显示国家名称?
我有 2 张桌子:
国家
countries_price
国家表包含等。id, name
countries_price表保持id, country_id, country_price
型号: (拉拉维尔和新星)
在乡村模型中(拉拉维尔):
public function countryPrice() {
return $this->hasOne('App\\CountryPrice');
}
在乡村价格模型(拉拉维尔):
public function countries()
{
return $this->hasMany('App\Country', 'id', 'country_id');
}
在国家模型(新星):
HasOne::make('CountryPrice'),
在乡村价格模型 (新星):
HasMany::make('Countries'),
我正在尝试:
在乡村价格模型 (拉拉维尔)
public function getCountryName() {
return Country::where('id', $this->country_id)->first()->name;
}
在乡村价格模型 (新星)
public function fields(Request $request)
{
return [
ID::make()->sortable(),
ID::make('Country ID','country_id'),
// TRYING TO PULL IN COUNTRY NAME HERE
Text::make('Country Name', function () {
$countryName= $this->getCountryName;
return $countryName;
}),
Text::make('Base Price', 'trip_cost'),
HasMany::make('Countries'),
];
}
我的错误:
应用\国家/地区价格::获取国家/地区名称必须返回关系实例
我不明白这个错误,需要帮助才能使它工作。任何帮助将不胜感激。
喵喵时光机
小怪兽爱吃肉
随时随地看视频慕课网APP