Laravel模型之间的关系不起作用
我有2种型号:一种用于用户的模型,一种用于客户。用户是客户
用户具有“ codigocli”字段,客户端具有“ codigo”字段,
我的模型之间的关系就是这样:
//User model
public function cliente()
{
return $this->hasOne(Cliente::class, 'codigo', 'codigocli');
}
//Cliente model
public function user()
{
return $this->belongsTo(User::class, 'codigocli', 'codigo');
}
我的数据库很好(我认为)客户端具有“ codigo”字段,用户具有'codigocli ' 场地。那我做错了什么?当我想用dd(auth() - > user() - clible())查询我的home.blade.php时,我什么都没有得到任何东西,尽管它向我显示了父对象罚款。
I have 2 models: one for users and one for clients. A user is a customer
User has a 'codigocli' field and client has a 'codigo' field
The relationships between my models are like this:
//User model
public function cliente()
{
return $this->hasOne(Cliente::class, 'codigo', 'codigocli');
}
//Cliente model
public function user()
{
return $this->belongsTo(User::class, 'codigocli', 'codigo');
}
My database is fine (I think) client has the 'codigo' field and users has the 'codigocli' field. So what am I doing wrong? When I want to query my home.blade.php with dd(auth()->user()-cliente()) I don't get anything, although it shows me the parent object fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
h
您在这里有一个OneToone关系,因此,如果您不更改ID名称,请尝试使用:
如果您更改ID名称:
H
You have an OneToOne relationship here so try this if you don't change id name:
if you change id name: