Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.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 5.1中的嵌套关联记录 我有三个数据库表。 型号_Php_Laravel 5_Laravel 5.1 - Fatal编程技术网

Php 获取Laravel 5.1中的嵌套关联记录 我有三个数据库表。 型号

Php 获取Laravel 5.1中的嵌套关联记录 我有三个数据库表。 型号,php,laravel-5,laravel-5.1,Php,Laravel 5,Laravel 5.1,存在CurrencyID关系和ProjectTypeID关系 我在尝试什么? 在我的Laravel 5.1代码中,我试图实现下面的sql语句,以便可以为每个ProjectType记录获取projecttypecurrencyprice记录。最后,它还应该为每个项目类型currencyPrice记录显示货币表中的记录 $ProjectTypes = \App\Models\project\ProjectType\ProjectType_Model ::with("p

存在
CurrencyID
关系和
ProjectTypeID
关系

我在尝试什么? 在我的Laravel 5.1代码中,我试图实现下面的sql语句,以便可以为每个
ProjectType记录
获取
projecttypecurrencyprice记录。最后,它还应该为每个
项目类型currencyPrice
记录显示
货币表中的记录

$ProjectTypes = \App\Models\project\ProjectType\ProjectType_Model
                ::with("projecttypecurrencyprice")
                ->with("projecttypecurrencyprice.Currency")
                ->get();
有什么问题吗?
我无法获取每个项目类型CurrencyPrice记录的货币记录。

对于
项目类型CurrencyPrice\u模型
您应通过以下方式更改
货币关系:

public function Currency()
{
     return $this->belongsTo('\App\Models\Currency_Model', "CurrencyID");
}
因为您在
tblprojecttypecurrencyprice
中有
CurrencyId
列,并且您与
tblcurrency
中的
ProjectTypeCurrencyPrice\u Model
没有任何连接。 并获取数据,而不是:

$ProjectTypes = \App\Models\project\ProjectType\ProjectType_Model
                ::with("projecttypecurrencyprice")
                ->with("projecttypecurrencyprice.Currency")
                ->get();
您可以用
省略第一个

$ProjectTypes = \App\Models\project\ProjectType\ProjectType_Model
                ::with("projecttypecurrencyprice.Currency")
                ->get();

顺便说一下,如果你开始这个项目,你应该考虑数据库结构的变化,并在PHP中读取PSR——你不应该使用<代码> ProjyType CurrrCyryPrice模型> /Case>作为你的模型名称,如果你真的不需要,MySQL < /P>中的<代码> ProjyType ID > /Cuth>列可以粘贴你的模型吗?您定义与其他提到的模型的关系的那部分您是否遇到了某种错误?
$ProjectTypes = \App\Models\project\ProjectType\ProjectType_Model
                ::with("projecttypecurrencyprice")
                ->with("projecttypecurrencyprice.Currency")
                ->get();
$ProjectTypes = \App\Models\project\ProjectType\ProjectType_Model
                ::with("projecttypecurrencyprice.Currency")
                ->get();