Complete PHPDocs, directly from the source
This package generates helper files that enable your IDE to provide accurate autocompletion. Generation is done based on the files in your project, so they are always up-to-date.
The 3.x branch supports Laravel 10 and 11. For older version, use the 2.x releases.
Require this package with composer using the following command:
composer require --dev barryvdh/laravel-ide-helper
[!NOTE]
If you encounter version conflicts with doctrine/dbal, please try:composer require --dev barryvdh/laravel-ide-helper --with-all-dependencies
This package makes use of Laravels package auto-discovery mechanism, which means if you don't install dev dependencies in production, it also won't be loaded.
If for some reason you want manually control this:
extra.laravel.dont-discover key in composer.json, e.g.
"extra": { "laravel": { "dont-discover": [ "barryvdh/laravel-ide-helper" ] } }
providers array in config/app.php:
If you want to manually load it only in non-production environments, instead you can add this to yourBarryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
AppServiceProvider with the register() method:
public function register() { if ($this->app->isLocal()) { $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } // ... }
Note: Avoid caching the configuration in your development environment, it may cause issues after installing this package; respectively clear the cache beforehand via
php artisan cache:clearif you encounter problems when running the commands
Check out this Laracasts video for a quick introduction/explanation!
php artisan ide-helper:generate - PHPDoc generation for Laravel Facades php artisan ide-helper:models - PHPDocs for modelsphp artisan ide-helper:meta - PhpStorm Meta fileNote: You do need CodeComplice for Sublime Text: https://github.com/spectacles/CodeComplice
You can now re-generate the docs yourself (for future updates)
php artisan ide-helper:generate
Note: bootstrap/compiled.php has to be cleared first, so run php artisan clear-compiled before generating.
This will generate the file _ide_helper.php which is expected to be additionally parsed by your IDE for autocomplete. You can use the config filename to change its name.
You can configure your composer.json to do this each time you update your dependencies:
"scripts": { "post-update-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postUpdate", "@php artisan ide-helper:generate", "@php artisan ide-helper:meta" ] },
You can also publish the config file to change implementations (ie. interface to specific class) or set defaults for --helpers.
php artisan vendor:publish --provider="Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider" --tag=config
The generator tries to identify the real class, but if it cannot be found, you can define it in the config file.
Some classes need a working database connection. If you do not have a default working connection, some facades will not be included.
You can use an in-memory SQLite driver by adding the -M option.
If you use real-time facades in your app, those will also be included in the generated file using a @mixin annotation and extending the original class underneath the facade.
Note: this feature uses the generated real-time facades files in the storage/framework/cache folder. Those files are generated on-demand as you use the real-time facade, so if the framework has not generated that first, it will not be included in the helper file. Run the route/command/code first and then regenerate the helper file and this time the real-time facade will be included in it.
You can choose to include helper files. This is not enabled by default, but you can override it with the --helpers (-H) option.
The Illuminate/Support/helpers.php is already set up, but you can add/remove your own files in the config file.
This package can generate PHPDocs for macros and mixins which will be added to the _ide_helper.php file.
But this only works if you use type hinting when declaring a macro.
Str::macro('concat', function(string $str1, string $str2) : string { return $str1 . $str2; });
If you don't want to write your properties yourself, you can use the command php artisan ide-helper:models to generate
PHPDocs, based on table columns, relations and getters/setters.
Note: this command requires a working database connection to introspect the table of each model
By default, you are asked to overwrite or write to a separate file (_ide_helper_models.php).
You can write the comments directly to your Model file, using the --write (-W) option, or
force to not write with --nowrite (-N).
Alternatively using the --write-mixin (-M) option will only add a mixin tag to your Model file,
writing the rest in (_ide_helper_models.php).
The class name will be different from the model, avoiding the IDE duplicate annoyance.
Please make sure to back up your models, before writing the info.
Writing to the models should keep the existing comments and only append new properties/methods. It will not update changed properties/methods.
With the --reset (-R) option, the whole existing PHPDoc is replaced, including any comments that have been made.
php artisan ide-helper:models "App\Models\Post"
/** * App\Models\Post * * @property integer $id * @property integer $author_id * @property string $title * @property string $text * @property \Illuminate\Support\Carbon $created_at * @property \Illuminate\Support\Carbon $updated_at * @property-read \User $author * @property-read \Illuminate\Database\Eloquent\Collection|\Comment[] $comments * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post newQuery() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post query() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post whereTitle($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post forAuthors(\User ...$authors) * … */
With the --write-mixin (-M) option
/** * … * @mixin IdeHelperPost */
By default, models in app/models are scanned. The optional argument tells what models to use (also outside app/models).
php artisan ide-helper:models "App\Models\Post" "App\Models\User"
You can also scan a different directory, using the --dir option (relative from the base path):
php artisan ide-helper:models --dir="path/to/models" --dir="app/src/Model"
You can publish the config file (php artisan vendor:publish) and set the default directories.
Models can be ignored using the --ignore (-I) option
php artisan ide-helper:models --ignore="App\Models\Post,App\Models\User"
Or can be ignored by setting the ignored_models config
'ignored_models' => [ App\Post::class, Api\User::class ],
where* methodsEloquent allows calling where<Attribute> on your models, e.g. Post::whereTitle(…) and automatically translates this to e.g. Post::where('title', '=', '…').
If for some reason it's undesired to have them generated (one for each column), you can disable this via config write_model_magic_where and setting it to false.
*_count propertiesYou may use the ::withCount method to count the number results from a relationship without actually loading them. Those results are then placed in attributes following the <columname>_count convention.
By default, these attributes are generated in the phpdoc. You can turn them off by setting the config write_model_relation_count_properties to false.
Laravel 9 introduced generics annotations in DocBlocks for collections. PhpStorm 2022.3 and above support the use of generics annotations within @property and @property-read declarations in DocBlocks, e.g. Collection<User> instead of Collection|User[].
These can be disabled by setting the config use_generics_annotations to false.
@comment based on DocBlockIn order to better support IDEs, relations and getters/setters can also add a comment to a property like table columns. Therefore a custom docblock @comment is used:
class Users extends Model { /** * @comment Get User's full name * * @return string */ public function getFullNameAttribute(): string { return $this->first_name . ' ' .$this->last_name ; } } // => after generate models /** * App\Models\Users * * @property-read string $full_name Get User's full name * … */
A new method to the eloquent models was added called newEloquentBuilder Reference where we can
add support for creating a new dedicated class instead of using local scopes in the model itself.
If for some reason it's undesired to have them generated (one for each column), you can disable this via config write_model_external_builder_methods and setting it to false.
If you are using relationships not built into Laravel you will need to specify the name and returning class in the config to get proper generation.
'additional_relation_types' => [ 'externalHasMany' => \My\Package\externalHasMany::class ],
Found relationships will typically generate a return value based on the name of the relationship.
If your custom relationships don't follow this traditional naming scheme you can define its return type manually. The available options are many and morphTo.
'additional_relation_return_types' => [ 'externalHasMultiple' => 'many' ],
If you need additional information on your model from sources that are not handled by default, you can hook in to the
generation process with model hooks to add extra information on the fly.
Simply create a class that implements ModelHookInterface and add it to the model_hooks array in the config:
'model_hooks' => [ MyCustomHook::class, ],
The run method will be called during generation for every model and receives the current running ModelsCommand and the current Model, e.g.:
class MyCustomHook implements ModelHookInterface { public function run(ModelsCommand $command, Model $model): void { if (! $model instanceof MyModel) { return; } $command->setProperty('custom', 'string', true, false, 'My custom property'); $command->unsetMethod('method'); $command->setMethod('method', $command->getMethodType($model, '\Some\Class'), ['$param']); } }
/** * MyModel * * @property integer $id * @property-read string $custom
If you need PHPDocs support for Fluent methods in migration, for example
$table->string("somestring")->nullable()->index();
After publishing vendor, simply change the include_fluent line in your config/ide-helper.php file into:
'include_fluent' => true,
Then run php artisan ide-helper:generate, you will now see all Fluent methods recognized by your IDE.
If you would like the factory()->create() and factory()->make() methods to return the correct model class,
you can enable custom factory builders with the include_factory_builders line in your config/ide-helper.php file.
Deprecated for Laravel 8 or latest.
'include_factory_builders' => true,
For this to work, you must also publish the PhpStorm Meta file (see below).
It's possible to generate a PhpStorm meta file to add support for factory design pattern.
For Laravel, this means we can make PhpStorm understand what kind of object we are resolving from the IoC Container.
For example, events will return an Illuminate\Events\Dispatcher object,
so with the meta file you can call app('events') and it will autocomplete the Dispatcher methods.
php artisan ide-helper:meta
app('events')->fire(); \App::make('events')->fire(); /** @var \Illuminate\Foundation\Application $app */ $app->make('events')->fire(); // When the key is not found, it uses the argument as class name app('App\SomeClass'); // Also works with app(App\SomeClass::class);
Note: You might need to restart PhpStorm and make sure
.phpstorm.meta.phpis indexed.Note: When you receive a FatalException: class not found, check your config (for example, remove S3 as cloud driver when you don't have S3 configured. Remove Redis ServiceProvider when you don't use it).
You can change the generated filename via the config meta_filename. This can be useful for cases where you want to take advantage of PhpStorm's support of the directory .phpstorm.meta.php/: all files placed there are parsed, should you want to provide additional files to PhpStorm.
The Laravel IDE Helper Generator is open-sourced software licensed under the [MIT


AI一键生成PPT,就用博思AIPPT!
博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。


AI赋能电商视觉革命,一站式智能商拍平台
潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。


企业专属的AI法律顾问
iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。


稳定高效的流量提升解决方案,助力品牌曝光
稳定高效的流量提升解决方案,助力品牌曝光


最新版Sora2模型免费使用,一键生成无水印视频
最新版Sora2模型免费使用,一键生成无水印视频


实时语音翻译/同声 传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。


选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

