【问题标题】:PhpStorm can't find Laravel helpersPhpStorm 找不到 Laravel 助手
【发布时间】:2018-09-21 15:05:20
【问题描述】:

我使用 PhpStorm 2018.1.4。我安装了包laravel-ide-helper。这允许 PhpStorm 看到模型方法,但它看不到来自 Laravel 助手的任何链接方法。例如,我在控制器中有以下代码:

return response()->file($path,['content-type' => 'application/pdf']); 

PhpStorm 对我说:

在 \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response 中找不到方法“文件”。

如何解决?

UPD:当然,安装包后,我运行了thees artisan commands:

php artisan ide-helper:generate
php artisan ide-helper:meta

【问题讨论】:

  • 旁注:从技术上讲,IDE 能够“找到 Laravel 助手”(response() 函数是助手)。但是它有一些问题(因为 Laravel 使用的 PHPDoc 以及总体上“如何正确记录它”)在链接时定位一些方法。 Darryl E. Clarke 描述得非常好。

标签: laravel phpstorm helper


【解决方案1】:

单独安装laravel-ide-helper 没有任何作用。您需要运行 artisan 命令来生成 phpstorm 将使用的文件。

php artisan ide-helper:generate

php artisan ide-helper:meta

将有助于 phpStorm 的自动补全。

更新:由于执行了这些,实际问题是laravel结构问题:

ResponseFactory 中实际上不存在帮助器 file()response() 返回 ResponseFactory 的结果),因此 IDE 帮助器无法映射到它。

file() 确实存在于 Facade 中,所以如果你这样做:

\Response::file($path,['content-type' => 'application/pdf']) 它将自动完成。

这是一种变通方法,但除非 file() 被添加到 laravel 级别的响应工厂,否则 ide 助手或 phpstorm 无能为力。

【讨论】:

  • 我的错,将其添加到问题中。当然,我是在安装后运行的
  • 这是结构问题。我已经更新了我的答案来说明原因。
猜你喜欢
  • 2018-08-23
  • 2016-02-08
  • 2013-09-02
  • 2015-05-30
  • 2016-03-08
  • 2013-07-31
  • 2017-01-02
  • 2022-06-27
  • 1970-01-01
相关资源
最近更新 更多