属于在本地而非生产上工作的关系

时间:2019-11-12 14:31:44

标签: laravel eloquent laravel-6

我在两个表的庄园和平面图上都有一个belongsTo和HasMany关系,一切都在我的本地工作,而不在生产上工作,

我尝试查看表输入,甚至清除并重新添加任何东西似乎都行不通。

d3floorplan的模型

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 

如果有人能指出正确的方向,我将不胜感激。预先感谢

更新-查看修补程序结果

App\buyproperty {#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: App\estates {#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,**
   },

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

App\buyproperty {#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: App\estates {#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: App\d3floorplan 
        {#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",                                    
      },                                                
     },

1 个答案:

答案 0 :(得分:0)

我能够通过安装Compoships https://github.com/topclaudy/compoships并在模型中对其进行配置来解决该错误,因为我在所有相互引用的模型上都有多个外键。

如果有人偶然发现了同一问题,您也可以参考Laravel Eloquent: multiple foreign keys for relationship,这也有很大帮助。

谢谢