Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 跨多个表的Laravel关系失败_Php_Laravel - Fatal编程技术网

Php 跨多个表的Laravel关系失败

Php 跨多个表的Laravel关系失败,php,laravel,Php,Laravel,我有以下表格 查表 id name ... public function settingsval(){ return $this->hasMany('App\AppSettingTypes','name','name.setting'); } 表格设置类型 id name level //references id on table check public function settings(){ return $this-&

我有以下表格

查表

 id
 name ...
    public function settingsval(){
       return $this->hasMany('App\AppSettingTypes','name','name.setting');
   }
表格设置类型

id
name
level //references id on table check
    public function settings(){
       return $this->hasMany('App\AppSetting','id','type');
   }
选项卡设置

type, //references type on table setting type
name
value
所以基本上我想返回所有带有设置的检查

所以我的模型中有

1.检查模型//参考表检查

 id
 name ...
    public function settingsval(){
       return $this->hasMany('App\AppSettingTypes','name','name.setting');
   }
在my AppSettingTypes//上引用表设置类型

id
name
level //references id on table check
    public function settings(){
       return $this->hasMany('App\AppSetting','id','type');
   }
所以在我的控制器上,我只是在做

CheckModel::with('settingsval')
但每次设置数组都是空的,即使有数据


有什么问题吗?

如果表的
设置类型
级别
列保存了对检查表的引用,则映射如下

public function settingsval(){
   return $this->hasMany('App\AppSettingTypes','level','id');
}
有很多定义

hasMany($related, $foreignKey, $localKey)

如果您可以为相关列使用更好的命名约定,例如
check\u id
,而不是
level
等等,则更好。如果
level
表的列
设置类型
保留了对check table的引用,则您的映射将是

public function settingsval(){
   return $this->belongsTo('YourCheckModelname','level');
}
并且在表
中检查
模型是否有如下映射

public function settingtype(){
       return $this->hasMany(\App\AppSettingTypes::class);
    }
Like wise如果表的
type
setting
保存了对settingtype表的引用,那么您的映射如下

 public function settings(){
       return $this->belongsTo('YourSettingTypeModelname','type');
    }
而在
设置类型中
模型有如下映射

public function settingsType(){
           return $this->hasMany('YourSettingModelName'::class);
        }
然后你必须在你的控制器里做

CheckModel::with('settingsval') //get all settingvalues

CheckModel::with('settingsval')现在为我提供最多appsetting类型,但我现在希望获得的设置不是appsettingtypes@GEOFFREYMWANGI如果还需要设置,则将
零件更新为
CheckModel::with('settingsval.settingsval')