Search code examples
phplaravelphpstormlaravel-bladephpdoc

How I can make variables autocomplete in the PhpStorm 9 for Blade templates?


I want PHPdoc blocks were considered within the blade template.

PhpStorm 9, Laravel 5.1, blade template file:

<?php
/* @var App\Models\User $user */
?>
...
<?= $user->email ?> <- autocomplete for the word "email" is working
...
{{ $user->email }} <- autocomplete not working

I tried different variants:

{{
/**
* @var App\Models\User $user
**/
}}
{{ /* @var App\Models\User $user */ }}
...
{{ $user->email }} <- autocomplete not working...
...
In such variant autocomplete works, but only within that block:
{{
/* @var App\Models\User $user */
$user->email
}}
...
{{ $user->email }} <- here does not work again...

How to make the autocomplete worked in all blocks for blade templates?


Solution

  • At the moment (December 2015) PhpStorm does not support PHPDoc comments in Blade templates using Blade syntax (especially for completing Blade variables).

    Please follow these tickets (star/vote/comment) to get notified on progress:


    UPDATE:

    The aforementioned WI-26501 ticket was implemented in 2017 and you can now use PHPDoc comments to declare variables and their types in Blade files.

    Be it PHP code blocks:

    <?php
    /** @var \App\Models\User $user */
    /** @var \App\MyService $someService */
    ?>
    

    ... or Blade-specific syntax (@php ... @endphp):

    @php /** @var \App\Models\User $user */ @endphp
    

    See the following blog post for details: https://blog.jetbrains.com/phpstorm/2017/02/code-completion-in-laravel-blade-templates/

    enter image description here