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.
Require this package with composer using the following command:
composer require --dev barryvdh/laravel-ide-helper
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
:
Barryvdh\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:clear
if 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.
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 generatePHPDocs, 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, orforce 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.The existing PHPDoc is replaced, or added if not found.With the --reset (-R)
option, the existing PHPDocs are ignored, and only the newly found columns/relations are saved as PHPDocs.
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
.
@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 canadd 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
.
Common column types (e.g. varchar, integer) are correctly mapped to PHP types (string
, int
).
But sometimes you may want to use custom column types in your database like geography
, jsonb
, citext
, bit
, etc. which may throw an "Unknown database type"-Exception.
For those special cases, you can map them via the config custom_db_types
. Example:
'custom_db_types' => [
'mysql' => [
'geography' => 'array',
'point' => 'array',
],
'postgresql' => [
'jsonb' => 'string',
'_int4' => 'array',
],
],
If you need additional information on your model from sources that are not handled by default, you can hook in to thegeneration 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 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 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.php
is 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 you want to take advantage the PhpStorm also supports the directory .phpstorm.meta.php/
which would parse any file places there, should your want provide additional files to PhpStorm.
This package is focused on Laravel development, but it can also be used in Lumen with some workarounds.Because Lumen works a little different, as it is like a bare bone version of Laravel and the main configurationparameters are instead located in bootstrap/app.php
, some alterations must be made.
While Laravel IDE Helper can generate automatically default Facades for code hinting,Lumen doesn't come with Facades activated. If you plan in using them, you must enablethem under the Create The Application
section, uncommenting this line:
// $app->withFacades();
From there, you should be able to use the create_alias()
function to add additional Facades into your application.
You can install Laravel IDE Helper in app/Providers/AppServiceProvider.php
,and uncommenting this line that registers the App Service Providers, so it can properly load.
// $app->register(App\Providers\AppServiceProvider::class);
If you are not using that line, that is usually handy to manage gracefully multiple Laravel/Lumen installations,you will have to add this line of code under the Register Service Providers
section of your bootstrap/app.php
.
if ($app->environment() !== 'production') {
$app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
After that, Laravel IDE Helper should work correctly. During the generation process,the script may throw exceptions saying that some Class(s) doesn't exist or there are some undefined indexes.This is normal, as Lumen has some default packages stripped away, like Cookies, Storage and Session.If you plan to add these packages, you will have to add them manually and create additional Facades if needed.
Currently, Lumen IDE Helper doesn't take into account additional Facades created under bootstrap/app.php
using create_alias()
,so you need to create a config/app.php
file and add your custom aliases under an aliases
array again, like so:
return [
'aliases' => [
'CustomAliasOne' => Example\Support\Facades\CustomAliasOne::class,
'CustomAliasTwo' => Example\Support\Facades\CustomAliasTwo::class,
//...
]
];
After you run php artisan ide-helper:generate
, it's recommended (but not mandatory) to rename config/app.php
to something else,until you have to re-generate the docs or after passing to production environment.Lumen 5.1+ will read this file for configuration parameters if it is present, and may overlap some configurations if it is completely populated.
The Laravel IDE Helper Generator is open-sourced software licensed under the MIT license
安装laravel-ide-helper composer包 https://packagist.org/packages/barryvdh/laravel-ide-helper 安装 composer require barryvdh/laravel-ide-helper 注册服务提供者 在config/app.php中providers下添加代码 'providers' => [ Barr
本文讲述laravel-ide-helper的安装方法。 phpstorm安装了laravel-ide-helper后可以实现代码提示、跟踪和自动补全,减少查看API文档的次数,提高开发效率。 laravel使用composer管理依赖包。依赖包是什么概念呢?世界上有很多PHP的项目,这些项目有很多功能模块可以共用的。比如发邮件的、模板解析的等等,为避免重复造轮子,达到共用代码的目的,于是把这些代
https://packagist.org/ 搜 barryvdh/laravel-ide-helper github上 https://github.com/barryvdh/laravel-ide-helper Install Require this package with composer using the following command: composer
一、扩展的地址 https://github.com/barryvdh/laravel-ide-helper 二、安装扩展 1、引入库: composer require barryvdh/laravel-ide-helper composer require doctrine/dbal 如果只想在开发环境上使用,请加上--dev composer require --dev barry
Eclipse提供了一个出色的插件m2eclipse ,它将Maven和Eclipse无缝集成在一起。 m2eclipse的一些功能如下 - 您可以从Eclipse运行Maven目标。 您可以使用自己的控制台查看Eclipse中Maven命令的输出。 您可以使用IDE更新maven依赖项。 您可以从Eclipse中启动Maven构建。 它基于Maven的pom.xml对Eclipse构建路径进行依
RT-Thread 为广大开发者提供了 VSCode 最好用的 MicroPython 插件 来帮助大家使用 MicroPython 来开发应用程序。该插件为 MicroPython 开发提供了功能强大的开发环境,主要特性如下: 便捷的开发板连接方式(串口、网络、USB) 支持基于 MicroPython 的代码智能补全与语法检查 支持 MicroPython REPL 交互环境 提供丰富的代码示
关于IDE每个人的喜好都不同,你可以使用较为独立的开发环境LiteIDE,也可以是VS或者Eclipse,甚至是notepad++,当然更不用说vim和emacs了。在这里,一种我比较喜欢的IDE:LiteIDE。 LiteIDE LiteIDE算是集成的非常好Go IDE了,编译,调试,代码补全,功能可谓应有尽有。而且免费,开源,基于QT所以还跨平台。其安装异常简单,从官网上下载对应平台的安装包
ScalaIDE 是一个 Eclipse 插件,提供 Scala 集成开发工具。主要的功能包括:同一个项目中混合编辑Scala/Java文件;Scala 编辑器支持语法高亮显示,代码自动完成,错误标记,链到定义处;代码调试;代码大纲视图等。
Nefarious IDE 是一个 Eclipse 用来开发 Google Go 编程语言程序的插件。 目前该项目的官方首页被禁止打开,不知何故。 目前实现的功能还比较简单,主要包括: - syntax highlighting (90%) - compile upon save and mark errors within project (60%) (go compiler required)
PlatformIO IDE 是下一代的物联网生态系统 PlatformIO 的集成开发环境。基于 Github Atom "hackable" 文本编辑器。支持多平台。 主要特点: 超级快速编码:C/C++ 智能自动代码完成和智能代码提示,通过多面板实现多项目工作流 嵌入式开发:无依赖的跨平台开发,支持 200+ embedded boards, 15+ development platform