Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.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
Mysql 多层次的深度在拉威尔有很多关系,口若悬河_Mysql_Laravel_Eloquent - Fatal编程技术网

Mysql 多层次的深度在拉威尔有很多关系,口若悬河

Mysql 多层次的深度在拉威尔有很多关系,口若悬河,mysql,laravel,eloquent,Mysql,Laravel,Eloquent,我有一个用户模型,他将添加客户,他将有永久地址(客户表中的id引用他们的地址),这将有分区,这将有地区,最后将有许多子分区 像这样的表有很多关系- - Users - Clients - PermanentAddresses (keeping the IDs of the subsequent child areas and client_id) - Divisions - Districts

我有一个用户模型,他将添加客户,他将有永久地址(客户表中的id引用他们的地址),这将有分区,这将有地区,最后将有许多子分区

像这样的表有很多关系-

    - Users
       - Clients
          - PermanentAddresses (keeping the IDs of the subsequent child areas and client_id)
             - Divisions
                - Districts
                    - Subdistricts
我如何从一个特定的分区获得所有客户,这些客户将属于某个地区,等等,一直到客户


所有这些级别都在驱动雄辩/连接查询。一些线索将不胜感激。这与不使用软件包的情况相同,但没有解决方案。但情况类似

这是一个很明显的例子

根据您的关系更改“永久地址.分区.地区.子分区”

此处
$subdirectid
是您的sub-district表的ID,如果您认为它可能不是ID,或者您的查询将是其他内容,则会根据该ID进行更改


我没有测试,但它应该可以工作。

您尝试过HasmanyThrough relationship或Laravel吗?我认为,或者您应该使用查询生成器,或者您必须在数据库中创建一个连接所有这些表的视图,然后您必须使用查询生成器查询该表。。。。Eloquent不能提供这么多层次的关系深度,最多2层与HasmanyThrough Eloquent是否生成“递归CTE”SQL?
Clients::whereHas('PermanentAddresses.Divisions.Districts.Subdistricts', function ($q) use ($subDistrictID) {
  $q->whereId($subDistrictID);
})->get();