【发布时间】:2015-09-15 10:25:03
【问题描述】:
我的数据库中有两个表:
- tbl_patient_master
- tbl_dept_master
tbl_patient_master 表的列是:
- 患者 ID
- 患者姓名
- dept_id
- created_at
- updated_at
tbl_dept_master 表的列是:
- dept_id
- 部门名称
- 部门类型
现在我想显示一个特定部门的患者列表。如果用户说“耳鼻喉科”,则应返回所有具有“耳鼻喉科”的患者。
为此,我在我的模型中创建了以下关系。
public function department()
{
return $this->belongsTo('App\Entities\Department','dept_id');
}
这段代码在我的控制器中获取数据:
$patients = $this->repository->with(array('department' => function ($query) use ($dept_name)
{
$query->where('dept_name', '=', $dept_name);
}))->all();
不幸的是,这将返回所有患者,而不仅仅是来自特定部门的患者。 我应该怎么做才能从特定部门获得所有患者?
谢谢。
【问题讨论】:
标签: php mysql laravel-4 laravel-5 eager-loading