dr5779 2015-08-06 07:14
浏览 22
已采纳

如何找出特定方法的确定位置(php / laravel)?

How to find out where a particular method is determined? Let's say in laravel I have this:

$this->_price = $this->product()->first()->price;

the class is Item extends Entity, but if I would check the Entity class it extends something else and that something else extends something more. The issue is that I can not see where this product() method is determined and I can not find it by using my IDE. How to debug such cases where you don't know from where something comes up?

  • 写回答

1条回答 默认 最新

  • dongtan7639 2015-08-06 07:19
    关注

    product() is a method that should define the relation - it is a method you need to add to your model.

    If a method does not exist, PHP first look for it in parent model, and if not found, Eloquent logic looks for the method in the Eloquent builder, and if not found, Eloquent builder looks for it in a query builder. At some point you are also able to register extensions to the builder that can add some methods. So in general, with Eloquent, it's quite hard to identify where the method exists :)

    But, as stated above, in this case this method should be defined by you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计