Skip to content

Commit

Permalink
Add TLDR section, update options (#1639)
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh authored Dec 29, 2024
1 parent a7fc73e commit 2a41415
Showing 1 changed file with 20 additions and 35 deletions.
55 changes: 20 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,27 @@ 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](https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518), 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:
- add the package to the `extra.laravel.dont-discover` key in `composer.json`, e.g.
```json
"extra": {
"laravel": {
"dont-discover": [
"barryvdh/laravel-ide-helper"
]
}
}
```
- Add the following class to the `providers` array in `config/app.php` (`bootstrap/providers.php` for Laravel 11+):
```php
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
```
If you want to manually load it only in non-production environments, instead you can add this to your `AppServiceProvider` with the `register()` method:
```php
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

## Usage

### TL;DR

Run this to generate autocompletion for Facades. This creates _ide_helper.php

```
php artisan ide-helper:generate
```

Run this to add phpdocs for your models. Add -RW to Reset existing phpdocs and Write to the models directly.
```
php artisan ide-helper:models -RW
```

If you don't want the full _ide_helper.php file, you can run add `--write-eloquent-helper` to the model command to generate small version, which is required for the `@mixin \Eloquent` to be able to add the QueryBuilder methods.

If you don't want to add all the phpdocs to your Models directly, you can use `--nowrite` to create a seperate file. The `--write-mixin` option can be used to only add a `@mixin` to your models, but add the generated phpdocs in a seperate file. This avoids having the results marked as duplicate.


_Check out [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_

- `php artisan ide-helper:generate` - [PHPDoc generation for Laravel Facades ](#automatic-phpdoc-generation-for-laravel-facades)
Expand All @@ -86,8 +71,6 @@ 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:
Expand Down Expand Up @@ -149,6 +132,8 @@ The class name will be different from the model, avoiding the IDE duplicate anno

> Please make sure to back up your models, before writing the info.
> You need the _ide_helper.php file to add the QueryBuilder methods. You can add --write-eloquent-helper/-E to generate a minimal version. If this file does not exist, you will be prompted for it.
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.
Expand Down

0 comments on commit 2a41415

Please # to comment.