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

racsuk's avatar
Level 8

Livewire Volt Single File - PHPStorm "import" not working

Hi,

I'm having trouble with livewire single file components. I love the ease of them, however, I'm having problems with PHPStorm just not giving me any fixes for code. For example, if I type "Episode" as a model, or "Validate" anywhere else in my code, I get a "suggestion" to fix by using "App\Models\Episode". And if I use the full namespace, I get the suggestion to remove the prefix.

I am not getting this in Livewire components, and it's requiring me to manually type out the namespace in the use section, which is slowing down my workflow considerably.

An example can be seen here: In my App directory (get the option to import): Image of it working

In my resources/views/livewire directory (don't get the option to import): image of it not working

0 likes
2 replies
LaryAI's avatar
Level 58

It sounds like you're experiencing an issue with PHPStorm's code suggestions and auto-imports not working correctly within Livewire single file components. This is likely due to the way PHPStorm handles different file types and directories. Here are a few steps you can take to try and resolve this issue:

  1. Ensure PHPStorm is Configured Correctly:

    • Make sure that PHPStorm recognizes your Livewire single file components as PHP files. You can do this by associating the file type with PHP in the settings.
      • Go to Settings > Editor > File Types.
      • Under Recognized File Types, find PHP and add the file extension of your Livewire components (e.g., .blade.php).
  2. Mark the Directory as a Resource Root:

    • PHPStorm might not be recognizing the resources/views/livewire directory as part of your project structure. You can mark it as a resource root.
      • Right-click on the resources/views/livewire directory in the Project view.
      • Select Mark Directory as > Resource Root.
  3. Invalidate Caches and Restart:

    • Sometimes, PHPStorm needs to refresh its caches to recognize new configurations.
      • Go to File > Invalidate Caches / Restart.
      • Select Invalidate and Restart.
  4. Check for Plugins:

    • Ensure you have the necessary plugins installed and updated. For Livewire, you might need the Laravel and Blade plugins.
      • Go to Settings > Plugins.
      • Search for Laravel and Blade and ensure they are installed and up-to-date.
  5. Use PHPDoc for Hints:

    • If PHPStorm is still not providing suggestions, you can use PHPDoc comments to help it understand the context.
      /** @var \App\Models\Episode $episode */
      $episode = new Episode();
      
  6. Custom File Templates:

    • If you frequently create Livewire components, consider creating a custom file template in PHPStorm that includes the necessary namespaces and use statements.
      • Go to Settings > Editor > File and Code Templates.
      • Create a new template for your Livewire components.

Here is an example of how you might structure a Livewire single file component to ensure PHPStorm recognizes the namespaces:

<template>
    <!-- Your Blade template here -->
</template>

<script>
    use Livewire\Component;
    use App\Models\Episode;

    class YourComponent extends Component
    {
        public $episode;

        public function mount()
        {
            $this->episode = new Episode();
        }

        public function render()
        {
            return view('livewire.your-component');
        }
    }
</script>

By following these steps, you should be able to improve PHPStorm's ability to provide code suggestions and auto-imports within your Livewire single file components. If the problem persists, consider reaching out to JetBrains support for more specific assistance related to PHPStorm.

racsuk's avatar
Level 8

Just to reply to the bot... Yes, I've tried all of that, its still not working. I have the laravel idea plugin.

Please or to participate in this conversation.