Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pwet84's avatar

Blade autocompletion (with PHPStorm)

For some reasons, it seems that PHPStorm can't autocomplete $var when I'm in a blade template.

For example, I have a VehicleController that pass a Vehicle object to my view :

public function view(Vehicle $vehicle)
{
    return view('vehicle.view', compact('vehicle'));
 }

In my blade template (/vehicles/view.blade.php) I have something like this :

<h1>{{ $vehicle->name }}</h1>

Nothing special here, it's working. The thing is, when I'm typing in my blade template "$vehicle..." then CTRL+ENTER, PHPStorm display a sad "No suggestions".

I'm new to PHPStorm and Laravel, so maybe :

  1. PHPStorm doesn't work that way / I am to lazy,
  2. There something to enable in PHPStorm for this to work,
  3. I'm missing something in my VehicleController or in my VehicleClass, so PHPStorm can't do the job properly.

Thanks for your reply.

Aurélien

0 likes
10 replies
willvincent's avatar

I'm fairly certain it can't be done because PHPStorm doesn't know anything about the variables that are passed to your template, so it has nowhere to get the information about what might be in those variables from which to provide autocomplete suggestions.

pwet84's avatar

@willvincent : thanks for your reply.

I am passing $vehicle variable to the view and since $vehicle is from the Vehicle class, so I thought PHPStorm would figure it out... :( I'm knew to working with PHPStorm and I thought I could gain some time.

So I have to manually check in the class to know properties or methods ?

PS : autocompletion works fine in VehicleController though.

Demers94's avatar

It makes sense that it can figure it out from the controller, since you're dealing with an instance of the Vehicle class directly. In your view however, the IDE has no idea what is available. It sees that you're passing an array containing an instance of Vehicle to the view, but it probably can't make the connection that this means it's acessible within the view file.

Maybe I'm understanding how an IDE does those things, but that's my guess as to why what you want to do isn't possible.

pwet84's avatar

I'm going back to Laravel development so I'm looking at this post again.

@tnorthcutt : thanks for your link.

I've tried what's in the example, by adding in my blade template :

<?php /** @var \Illuminate\Support\ViewErrorBag $errors */ ?>

And it works. If I type "{{ $errors->" + CTRL + ENTER, I have autocompletion.

However, if I try :

<?php /** @var \App\Vehicle $vehicle */ ?>

And then "{{ $vehicle->" + CTRL + ENTER, nothing happens.

What am I doing wrong ? Do I need to specify something in my Vehicle model ? If so, what ?

For the record, if I manually type

{{ $vehicle->engine}}

It does display the engine, so the $vehicle variable is well passed to the blade template.

Ironyh's avatar

Maybe you need docblocks in the vehicle class?

pwet84's avatar

I'm getting closer.

I have now this in my Vehicle class/model (as suggested by @Ironyh) :

    /**
     * @var string
     */
    protected $engine;

    /**
     * @return string
     */
    public function getEngine()
    {
        return $this->engine;
    }

Now in blade, if I do "$vehicle->" + CTRL + ENTER :

  • autocompletion doesn't show $engine (seems normal since it's protected right ?)
  • autocompletion show getEngine()

However, if I check the page :

  • $vehicle->engine : display the engine
  • $vehicle->getEngine() : display nothing

So about my initial question "how to have autocompletion in blade" I guess it's ok. But I have to figure out why getEngine() returns nothing.

Thanks for your replies.

EDIT :

I removed the :

    /**
     * @var string
     */
    protected $engine;

And now it works with getEngine() : visible in autocompletion and display the right data. Have no idea why though...

bretto36's avatar

For anyone who stumbles across this, my recommendation for getting the docblocks added automatically would be to use the package - https://github.com/barryvdh/laravel-ide-helper

It automatically generates model doc blocks based on the DB. So auto completion is automatic and you can stop writing them yourself.

stevemoretz's avatar

@bretto36 I love that library, but does it generate those docs inside blade from controllers? I can't find anything about what you are saying.

Please or to participate in this conversation.