barryvdh/laravel-ide-helper
Generates accurate PHPDoc helper files for Laravel to improve IDE autocompletion and type hints. Create _ide_helper.php for facades, add or export model PHPDocs, fluent methods, factory builders, and PhpStorm container metadata—kept in sync with your project.
Installation:
composer require --dev barryvdh/laravel-ide-helper
Generate Facade PHPDocs (core use case):
php artisan ide-helper:generate
This creates _ide_helper.php in your project root, enabling IDE autocompletion for Laravel facades.
Verify IDE Integration:
Settings > Languages & Frameworks > PHP > PHP Doc Parsers and ensure the _ide_helper.php file is included.Debugging a Facade Method:
Route::get('/posts', function () {
return Post::where('published', true)->get(); // Autocomplete works for `where()` and `get()`
});
Without the helper, IDEs show generic Builder methods. After running ide-helper:generate, you get full method signatures (e.g., where(string $column, mixed $operator = null, mixed $value = null)).
Facade Autocompletion (Daily Use)
php artisan ide-helper:generate after dependency updates or when adding new facades.composer.json:
"scripts": {
"post-update-cmd": [
"@php artisan ide-helper:generate"
]
}
Model PHPDocs (Development Workflow)
php artisan ide-helper:models --write
php artisan ide-helper:models App\Models\User App\Models/Post
php artisan ide-helper:models --write-mixin
Custom Facades/Real-Time Facades
Route::cache()), trigger the facade first, then regenerate:
php artisan route:cache
php artisan ide-helper:generate
Macros and Mixins
Str::macro('concat', function(string $str1, string $str2): string { ... });
php artisan ide-helper:generate
-M for SQLite if your default connection fails:
php artisan ide-helper:models -M
php artisan ide-helper:models --ignore="App\Models\Test*"
php artisan ide-helper:models --dir="app/Domain/Models"
// config/ide-helper.php
'include_fluent' => true,
Then regenerate.Real-Time Facades Not Included
php artisan route:cache
php artisan ide-helper:generate
Duplicate PHPDocs in Models
--write) may cause duplicates.--write-mixin to separate docs into _ide_helper_models.php.Database Connection Errors
ide-helper:models fails if the default connection is misconfigured.-M for SQLite or specify a working connection in .env.Macros Without Type Hints
Str::macro('slugify', function(string $str): string { ... });
IDE Not Picking Up Helpers
_ide_helper.php is in the "PHP Doc Parsers" list.intelephense.environment.php.projects in settings:
{
"projects": ["your-project-path/_ide_helper.php"]
}
_ide_helper.php for missing methods/facades.config/ide-helper.php) may override defaults.Custom Model Hooks
ModelHookInterface for unsupported model features:
class CustomHook implements ModelHookInterface {
public function run(ModelsCommand $command, Model $model) {
$command->setProperty('custom_field', 'string', false, false, 'Custom value');
}
}
config/ide-helper.php:
'model_hooks' => [CustomHook::class],
Custom Relationship Types
'additional_relation_types' => [
'customHasMany' => \Your\CustomHasMany::class,
],
Generics Annotations (Laravel 9+)
'use_generics_annotations' => true,
@property-read Collection<User> $users
Exclude Magic Methods
where* methods:
'write_model_magic_where' => false,
--only to target specific facades:
php artisan ide-helper:generate --only="Auth,Cache"
php artisan ide-helper:generate && git diff --exit-code
'facades' => [
'Auth' => Illuminate\Support\Facades\Auth::class,
// Exclude others if not used
],
How can I help you explore Laravel packages today?