0

我需要帮助在 eloquent 中编写一个查询,该查询首先在 zipcodes 表中搜索一个城市,然后使用它找到的那些 id 来查找该邮政编码列表中存在的活动。

表:邮政编码 - id(代表邮政编码) - 城市

活动 - id - 名称 - zipcodes_id(与 zipcodes 表相关)

没关系,我终于想通了。

        $zipcodes = Zipcodes::has('activities')->where('city', '=', $city)->get();
        foreach ($zipcodes as $zipcode)
        {
            echo $zipcode->activities;
        }

回报:

[{"id":1,"activity_type":2,"name":"Four Peaks Grill & Tap","zipcodes_id":85032}]
4

1 回答 1

0

没关系,我终于想通了。

$zipcodes = Zipcodes::has('activities')->where('city', '=', $city)->get();
foreach ($zipcodes as $zipcode)
{
    echo $zipcode->activities;
}

回报:

[{"id":1,"activity_type":2,"name":"Four Peaks Grill & Tap","zipcodes_id":85032}]
于 2013-07-31T19:34:16.140 回答