如何让 PhpStorm 在 blade-files 中自动完成外观

How to get PhpStorm to autocomplete facades in blade-files

当使用 @if (Auth::check()) 时,PhpStorm 无法识别 Auth

如何告诉 PhpStorm Auth\Illuminate\Support\Facades\Auth

已测试:

@php
use Illuminate\Support\Facades\Auth;
/** @var \Illuminate\Support\Facades\Auth Auth */
class Auth extends \Illuminate\Support\Facades\Auth {}
@endphp

@use(\Illuminate\Support\Facades\Auth)

都没成功,还是得到"Undefined Class Auth"

编辑 1:

如果 class Auth extends \Illuminate\Support\Facades\Auth {} 行在另一个文件中,例如“_ide_helper.php”,那么它在 blade 文件中不起作用。

要获得正确的 class 使用 @if (\Auth::check())!

IDE 无法识别通过外观访问的方法。 laravel-ide-helper 是解决此问题的流行软件包。它生成 IDE 理解的自定义帮助文件。这不是一个完整的解决方案,但它涵盖了 laravel 类 的大部分内容并有助于自动完成。这是您的选择。

  1. https://gist.github.com/barryvdh/5227822

  2. 下载 laravel 的最新 _ide_helper.php 文件并将其拖放到您的项目中
  3. 安装 laravel-ide-helper 包并让它动态生成帮助文件。 https://github.com/barryvdh/laravel-ide-helper

我个人建议安装该软件包。