归属于在本地但不在生产上工作的关系



我有两张桌子的地产和平面图的belongsTo和HasMany关系,everthing适用于我的本地,但不适用于生产,

我试过查看表输入,甚至清除和重新添加似乎都不起作用。

d3平面布置图的模型

class d3floorplan extends Model {
// 
protected $table = 'd3floorplan';
public function estates()
{
return $this->belongsTo('id',estates::class);
}
public function estate_house_types(){
return $this->hasMany(estate_house_types::class,'estate_id','house_type_id');
}
public function buyproperty(){
return $this->hasMany(buyproperty::class,'estate_id','house_type_id');
}}

买方模型

class buyproperty extends Model{
protected $table = 'buyproperty';
public function d3floorplan(){
return $this->belongsTo(d3floorplan::class, 'estate_id', 'id');

}}

控制器代码

$getproperties = buyproperty::with('d3floorplan')->get();

刀片出现错误

Trying to get property 'd3floor_plan_img_sale' of non-object 

如果有人能给我指明正确的方向,我将不胜感激。提前感谢

更新-查看Tinker结果

Appbuyproperty {#3016
id: 35,
created_at: "2019-11-12 13:37:06",
updated_at: "2019-11-12 13:37:06",
estate_id: 2,
block_id: 157,
house_type_id: 26,
kitchen_id: 94,
tile_id: 42,
floor_id: 61,
customer_name: "skufndff fdf",
customer_email: "4343@aol.com",
mobile_number: "0939023902",
age_bracket: "22",
accept_terms: 1,
Amount_Paid: "323232",
payment_status: "1",
estates: Appestates {#3022
id: 2,
created_at: "2019-11-03 16:36:33",
updated_at: "2019-11-03 16:36:33",
Estate_name: "Blueocen",
Estate_logo: "BlueLOGO.jpg",
status: "1",
display_pic: Blueocean3.jpg",
},
**d3floorplan: null,**
},

**来自本地开发环境的相同修补程序结果**

Appbuyproperty {#3016
id: 35,
created_at: "2019-11-12 13:37:06",
updated_at: "2019-11-12 13:37:06",
estate_id: 2,
block_id: 157,
house_type_id: 26,
kitchen_id: 94,
tile_id: 42,
floor_id: 61,
customer_name: "skufndff fdf",
customer_email: "4343@aol.com",
mobile_number: "0939023902",
age_bracket: "22",
accept_terms: 1,
Amount_Paid: "323232",
payment_status: "1",
estates: Appestates {#3022
id: 2,
created_at: "2019-11-03 16:36:33",
updated_at: "2019-11-03 16:36:33",
Estate_name: "Blueocen",
Estate_logo: "BlueLOGO.jpg",
status: "1",
display_pic: Blueocean3.jpg",
},
estate_blocks: null,
estate_house_types: null,
estate_lookup_house_types: null,
d3floorplan: Appd3floorplan 
{#3039               
id: 2,                                          
created_at: "2019-10-09 21:53:14",              
updated_at: "2019-10-09 21:53:16",              
estate_id: 2,                                   
house_type_id: 1,                               
d3floorplan_title: "Test Title",                
d3floor_plan_img: "2brfairfield-bdr-01.png",    
d3floor_plan_img_sale: "1bedsale.jpg",          
status: "1",                                    
},                                                
},

我通过安装Composships解决了这个错误https://github.com/topclaudy/compoships并在我的模型中配置它,因为我在所有相互引用的模型上都有多个外键。

如果有人偶然发现了同样的问题,你也可以参考Laravel Eloquent:关系的多个外键也有很大帮助。

感谢

最新更新