php - hasManyThrough() - 此集合实例上不存在属性 [价格]
问题描述
项目:
- id
- user_id
用户:
- id
- country_id
运费价格 - id - country_from_id - country_to_id - 价格
项目.php
public function localPrice()
{
return $this->hasManyThrough(
'App\FreightPrice',
'App\User',
'id',
'country_from_id',
'user_id',
'country_id'
);
}
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
用户.php
public function countryFromId(){
return $this->hasMany('App\FreightPrice');
}
FreightPricePrice.php
public function user(){
return $this->belongsTo('App\User');
}
我需要使用“user_id”获取项目的“country_from_id”。
此代码返回错误:“此集合实例上不存在属性 [价格]。”
这是查询:“select freight_prices
.*, users
. id
from freight_prices
inner join users
on users
. id
= freight_prices
. country_from_id
where users
. id
is null”。
解决方案
推荐阅读
- c# - html表中的实体框架多对多关系
- babeljs - package.json 'dependencies' 值中的 `workspace:` 前缀是什么意思?
- splunk - 如果消息为 x 超过 5 分钟,则 Splunk 搜索
- vuejs2 - 在 vue 的挂载钩子中如何使用数据对象变量?
- python - 偶数和奇数函数
- cartopy - 转换为 OSGB 的纬度/经度在绘制时有偏移
- mysql - 无法让 WP CLI 与 docker 一起使用:不允许 mbind
- xamarin - Xamarin 表单条目
- json - 在 Springboot 中为 @RestController 配置自定义 ObjectMapper
- amazon-web-services - Lambda 写入 DynamoDB IAM 角色不起作用