简体   繁体   中英

How to get PhpStorm to autocomplete facades in blade-files

When using @if (Auth::check()) , PhpStorm doesn't recognize the Auth .

How do I tell PhpStorm that Auth is \\Illuminate\\Support\\Facades\\Auth ?

Tested:

@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)

neither worked, still get "Undefined Class Auth"

Edit 1:

the class Auth extends \\Illuminate\\Support\\Facades\\Auth {} line works if it's in another file, for example, the "_ide_helper.php", having it inside the blade file doesn't work.

IDE won't recognize methods accessed via the facade. laravel-ide-helper is a popular package that solves this problem. It generates a custom helper file that the IDE understands. This is not a complete solution but it covers most of laravel classes and helps with autocompletion. Here are your options.

  1. Download and drop the latest _ide_helper.php file for laravel into your project from https://gist.github.com/barryvdh/5227822

  2. Install the laravel-ide-helper package and let it generate a helper file on the fly. https://github.com/barryvdh/laravel-ide-helper

I'd personally suggest installing the package.

要获得正确的类,请使用@if (\\Auth::check())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM