我要做的是添加与我的数据透视表的关系。我有一个独特的场景,我的数据透视表需要它自己在角色表上的 has_one 关系。有人看到专门为数据透视表创建 Eloquent 模型有问题吗?另外,如果我要创建这个模型,有没有什么办法可以让下面的模型返回?
$user = User::where('id', '=', 1);
$pivot = $user->hasmanyexample()->pivot();
我特别希望能够执行以下操作:
$user = User::where('id', '=', 1);
$pivot = $user->example()->pivot();
// class Example_User
// public function role() { return $this->has_one('Role', 'role_id'); }
$role = $pivot->role();