为什么即使我在Laravel中删除了关系,仍然有很多关系仍在工作 [英] Why hasMany Relation still working even i removed relation in Laravel

查看:85
本文介绍了为什么即使我在Laravel中删除了关系,仍然有很多关系仍在工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上面的两个模型中,我都评论了方法itemDestribution(),但它仍然有效

In the above both models i commented the method itemDestribution() but still it is working

推荐答案

由于以下原因,该关系显示数据.

This relation displays a Data because of following reasons.

  1. 在您的ItemDestributionModel中,您已经设置了与UserModelItemModel的关系.

  1. In your ItemDestributionModel, You have set relation with UserModel and ItemModel both.

在您的ItemModelUserModel中,您没有声明任何公共函数并添加关系类.

In your ItemModel and UserModel you haven't declare any public function and add Relation Class.

当您调用UserModel时,它将在ItemDestributionModel中找到hasMany关系,并且user()函数可用于belongsTo关系.

When you call UserModel it will find hasMany Relationship in ItemDestributionModel and user() function is available with belongsTo relationship.

这就是为什么laravel在不声明公共功能的情况下获取数据的原因.但是您应该在公共函数内部声明关系. :)

That's why laravel fetch data without declaring public function. But you should declare relationship inside public function. :)

这篇关于为什么即使我在Laravel中删除了关系,仍然有很多关系仍在工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆