【发布时间】:2017-09-25 20:39:48
【问题描述】:
我有这个(简化的)表结构:
users
- id
- type (institutions or agents)
institutions_profile
- id
- user_id
- name
agents_profile
- id
- user_id
- name
我需要在Users 模型上创建profile 关系,但以下不起作用:
class User extends Model
{
public function profile()
{
if ($this->$type === 'agents')
return $this->hasOne('AgentProfile');
else
return $this->hasOne('InstitutionProfile');
}
}
我怎样才能实现这样的目标?
【问题讨论】:
标签: laravel eloquent relationships