nonsapiens / laravel-ide-helper
Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.
Requires
- php: >=5.4.0
- barryvdh/reflection-docblock: ^2.0.4
- illuminate/console: ^5.0,<5.7
- illuminate/filesystem: ^5.0,<5.7
- illuminate/support: ^5.0,<5.7
- symfony/class-loader: ^2.3|^3.0
Requires (Dev)
- doctrine/dbal: ~2.3
- illuminate/config: ^5.0,<5.7
- illuminate/view: ^5.0,<5.7
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
Suggests
- doctrine/dbal: Load information from the database about models for phpdocs (~2.3)
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- dev-master / 2.3.x-dev
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- 1.11.x-dev
- v1.11.6
- v1.11.5
- v1.11.4
- v1.11.3
- v1.11.2
- v1.11.1
- v1.11.0
- v1.10.0
- v1.9.3
- v1.9.2
- v1.9.1
- v1.9.0
- v1.8.1
- v1.8.0
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.1
- v1.6.0
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v1.0.0-beta2
- v1.0.0-beta1
- dev-revert-624-Fix/623
- dev-revert-303-master
This package is auto-updated.
Last update: 2022-06-04 11:35:27 UTC
README
For Laravel 4.x, check version 1.11
Complete phpDocs, directly from the source
Check out this Laracasts video for a quick introduction/explanation!
php artisan ide-helper:generate
- phpDoc generation for Laravel Facadesphp artisan ide-helper:models
- phpDocs for modelsphp artisan ide-helper:meta
- PhpStorm Meta file
This package generates a file that your IDE understands, so it can provide accurate autocompletion. Generation is done based on the files in your project, so they are always up-to-date. If you don't want to generate it, you can add a pre-generated file to the root folder of your Laravel project (but this isn't as up-to-date as self generated files).
- Generated version for L5: https://gist.github.com/barryvdh/5227822
- Generated version for Lumen: https://gist.github.com/barryvdh/be17164b0ad51f832f20
- Generated Phpstorm Meta file: https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67
Note: You do need CodeComplice for Sublime Text: https://github.com/spectacles/CodeComplice
Install
Require this package with composer using the following command:
composer require barryvdh/laravel-ide-helper
After updating composer, add the service provider to the providers
array in config/app.php
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
To install this package on only development systems, add the --dev
flag to your composer command:
composer require --dev barryvdh/laravel-ide-helper
In Laravel, instead of adding the service provider in the config/app.php
file, you can add the following code to your app/Providers/AppServiceProvider.php
file, within the register()
method:
public function register() { if ($this->app->environment() !== 'production') { $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } // ... }
This will allow your application to load the Laravel IDE Helper on non-production enviroments.
Automatic phpDoc generation for Laravel Facades
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.
You can configure your composer.json to do this after each commit:
"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
or --sublime
.
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.
Automatic phpDocs for models
You need to require
doctrine/dbal: ~2.3
in your own composer.json to get database columns.
composer require doctrine/dbal
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. You can write the comments directly to your Model file, using the --write (-W)
option. By default, you are asked to overwrite or write to a separate file (_ide_helper_models.php
). You can force No with --nowrite (-N)
.
Please make sure to backup your models, before writing the info.
It 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 Post
/** * An Eloquent Model: 'Post' * * @property integer $id * @property integer $author_id * @property string $title * @property string $text * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property-read \User $author * @property-read \Illuminate\Database\Eloquent\Collection|\Comment[] $comments */
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 Post 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="Post,User"
Note: With namespaces, wrap your model name in double-quotes ("
): php artisan ide-helper:models "API\User"
, or escape the slashes (Api\\User
)
For properly recognition of Model
methods (i.e. paginate
, findOrFail
) you should extend \Eloquent
or add
/** @mixin \Eloquent */
for your model class.
Automatic phpDocs generation for Laravel Fluent methods
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,
And then run php artisan ide-helper:generate
, you will now see all of the Fluent methods are recognized by your IDE.
PhpStorm Meta for Container instances
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');
Pre-generated example: https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67
Note: You might need to restart PhpStorm and make sure
.phpstorm.meta.php
is indexed. Note: When you receive a FatalException about a class that is 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).
Lumen Install
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 barebone version of Laravel and the main configuration parameters are instead located in bootstrap/app.php
, some alterations must be made.
Enabling Facades
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 enable them 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.
Adding the Service Provider
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.
Adding Additional Facades
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 enviroment. Lumen 5.1+ will read this file for configuration parameters if it is present, and may overlap some configurations if it is completely populated.
License
The Laravel IDE Helper Generator is open-sourced software licensed under the MIT license