首页 > 解决方案 > 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. idfrom freight_pricesinner join userson users. id= freight_prices. country_from_idwhere users. idis null”。

标签: phplaravel

解决方案


推荐阅读