【问题标题】:Laravel and Phpstorm: model methods not recogniced in collectionsLaravel 和 Phpstorm:集合中无法识别的模型方法
【发布时间】:2015-05-28 07:41:55
【问题描述】:

当我做类似的事情时: $solicitud = Solicitud::find($id); $extras = $solicitud->extras();

PHPstorm 无法将 $solicitud 识别为 Solicitud 模型,并在 extras() 方法中显示警告:“method extras is not found in Illuminate/Support/Collection|static”

如果我使用@var 注释,警告就会消失,但有一种形式可以自动修复这个问题吗?

【问题讨论】:

  • 同样的问题:)。你在哪里有 @var 注释? (这个解决方案我可以接受)
  • 变量第一次出现之前的任何地方,像这样: /** * @var Solicitud $solicitud */

标签: php laravel phpstorm


【解决方案1】:

我以前在 Laravel 4 中遇到过这个问题,当时模型过去只是扩展 \Eloquent,虽然这在编程上很好,但 PHPStorm 不知道 \Eloquent 是什么,因为它在 laravel 运行引导后的唯一设置在配置文件中注册别名。

在您的模型中,您只需使其扩展 Illuminate\Database\Eloquent\Model

use Illuminate\Database\Eloquent\Model as Eloquent;

class Solicitud extends Eloquent {
    // Usual model code
}

【讨论】:

  • 我认为问题不在于 Eloquent 方法完成(它适用于您的答案),而是在 find(如 comments()extras())之后自定义 Solicitud 方法完成。无论如何,也许我误解了你的答案或问题:/
  • 你说得对,rap-2-h。方法完成不适用于对象集合。
猜你喜欢
  • 2017-07-24
  • 1970-01-01
  • 1970-01-01
  • 2015-10-28
  • 2018-05-27
  • 2013-12-23
  • 1970-01-01
  • 2014-12-17
  • 2017-05-25
相关资源
最近更新 更多