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:
-
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, findPHPand add the file extension of your Livewire components (e.g.,.blade.php).
- Go to
- 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.
-
Mark the Directory as a Resource Root:
- PHPStorm might not be recognizing the
resources/views/livewiredirectory as part of your project structure. You can mark it as a resource root.- Right-click on the
resources/views/livewiredirectory in the Project view. - Select
Mark Directory as>Resource Root.
- Right-click on the
- PHPStorm might not be recognizing the
-
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.
- Go to
- Sometimes, PHPStorm needs to refresh its caches to recognize new configurations.
-
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
LaravelandBladeand ensure they are installed and up-to-date.
- Go to
- Ensure you have the necessary plugins installed and updated. For Livewire, you might need the Laravel and Blade plugins.
-
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();
- If PHPStorm is still not providing suggestions, you can use PHPDoc comments to help it understand the context.
-
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.
- Go to
- If you frequently create Livewire components, consider creating a custom file template in PHPStorm that includes the necessary namespaces and use statements.
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.

