【发布时间】:2018-08-07 05:54:37
【问题描述】:
我有两个模型 Base_voter 和 Custom_list
Custom_list.php
public function base_voters()
{
return $this->hasMany('App\Models\Base_voter', 'custom_pivot_base', 'custom_list_id', 'base_voter_id');
}
Base_voter
public function custom_lists()
{
return $this->belongsToMany('App\Models\Custom_list', 'custom_pivot_base', 'custom_list_id', 'base_voter_id');
}
有一个包含两列的数据透视表 custom_pivot_base
custom_list_id, base_voter_id
现在,我需要检索其 customer_list_id = 1 和 street = $street,其中 city = $city 的 base_voter 列表。这些地址和城市列在 base_voters 表中。我如何在 laravel 中用 eloquent 做到这一点
【问题讨论】:
-
这两个模型应该是
belongsToMany关系。